當前位置: 首頁>>代碼示例>>Java>>正文


Java ParseError類代碼示例

本文整理匯總了Java中com.android.volley.ParseError的典型用法代碼示例。如果您正苦於以下問題:Java ParseError類的具體用法?Java ParseError怎麽用?Java ParseError使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ParseError類屬於com.android.volley包,在下文中一共展示了ParseError類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected com.android.volley.Response<String> parseNetworkResponse(NetworkResponse response) {
    this.statusCode = response.statusCode;
    this.responseHeaders = response.headers;
    /* Get the response data */
    try {
        String json = "";
        if (response.data != null) {
            json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        }
        String log = "%1$s\nResponse code: %2$s\nResponse body: %3$s";
        VolleyLog.v(log, getUrl(), statusCode, json);
        if (statusCode >= 200 && statusCode < 300) {
            /* Return the parsed result in a response wrapper */
            return shouldCache() ?
                    success(json, parseIgnoreCacheHeaders(response)) :
                    success(json, parseCacheHeaders(response));
        } else {
            return error(new ServerError(response));
        }
    } catch (UnsupportedEncodingException e) {
        return error(new ParseError(e));
    }
}
 
開發者ID:octaware,項目名稱:super-volley,代碼行數:25,代碼來源:BaseRequest.java

示例2: doParse

import com.android.volley.ParseError; //導入依賴的package包/類
/**
 * The real guts of parseNetworkResponse. Broken out for readability.
 */
private Response<Bitmap> doParse(NetworkResponse response) {
    byte[] data = response.data;
    BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
    Bitmap bitmap = null;
    if (mMaxWidth == 0 && mMaxHeight == 0) {
        if (mDecodeConfig != null) {
            decodeOptions.inPreferredConfig = mDecodeConfig;
        }
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
    } else {
        bitmap = ImageUtils.compressBitmap(data, mMaxWidth, mMaxHeight);
    }

    if (bitmap == null) {
        return Response.error(new ParseError());
    } else {
        return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
    }
}
 
開發者ID:HanyeeWang,項目名稱:GeekZone,代碼行數:23,代碼來源:BaseImageRequest.java

示例3: checkErrorType

import com.android.volley.ParseError; //導入依賴的package包/類
public static String checkErrorType(VolleyError error) {
    String str = "";
    if (error instanceof NoConnectionError) {
        str = ErrorCode.IS_NOT_NETWORK;
    } else if (error instanceof AuthFailureError) {
        str = ErrorCode.AUTH_FAILED;
    } else if (error instanceof TimeoutError) {
        str = ErrorCode.CONNECTION_TIMEOUT;
    } else if (error instanceof ParseError) {
        str = ErrorCode.PARSE_DATA_ERROR;
    } else if (error instanceof ServerError) {
        str = ErrorCode.SERVER_ERROR;
    } else if (error instanceof HttpError) {
        HttpError httpError = (HttpError) error;
        str = httpError.getMessage();
        if (TextUtils.isEmpty(str)) {
            str = ErrorCode.REQUEST_ERROR;
        }
    } else {
        str = ErrorCode.REQUEST_ERROR;
    }
    return str;
}
 
開發者ID:DoloresTeam,項目名稱:dolores-android,代碼行數:24,代碼來源:HttpUtil.java

示例4: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response)
{
	try
	{
		String jsonString =
				new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		return Response.success(new JSONArray(jsonString),
				HttpHeaderParser.parseCacheHeaders(response));
	} catch (UnsupportedEncodingException e)
	{
		return Response.error(new ParseError(e));
	} catch (JSONException je)
	{
		return Response.error(new ParseError(je));
	}
}
 
開發者ID:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:18,代碼來源:BaseArrayJsonRequest.java

示例5: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response)
{
	try
	{
		String jsonString = new String(response.data,
				HttpHeaderParser.parseCharset(response.headers));
		//Allow null
		if (jsonString == null || jsonString.length() == 0)
		{
			return Response.success(null, HttpHeaderParser.parseCacheHeaders(response));
		}
		return Response.success(new JSONObject(jsonString),
				HttpHeaderParser.parseCacheHeaders(response));
	} catch (UnsupportedEncodingException e)
	{
		return Response.error(new ParseError(e));
	} catch (JSONException je)
	{
		return Response.error(new ParseError(je));
	}
}
 
開發者ID:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:23,代碼來源:BaseJsonRequest.java

示例6: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response)
{
	try
	{
		String jsonString = new String(response.data,
				HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
		return Response.success(new JSONObject(jsonString),
				HttpHeaderParser.parseCacheHeaders(response));
	} catch (UnsupportedEncodingException e)
	{
		return Response.error(new ParseError(e));
	} catch (JSONException je)
	{
		return Response.error(new ParseError(je));
	}
}
 
開發者ID:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:18,代碼來源:BaseMultipartJsonRequest.java

示例7: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response)
{
	try
	{
		String jsonString = new String(response.data,
				HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
		return Response.success(new JSONArray(jsonString),
				HttpHeaderParser.parseCacheHeaders(response));
	} catch (UnsupportedEncodingException e)
	{
		return Response.error(new ParseError(e));
	} catch (JSONException je)
	{
		return Response.error(new ParseError(je));
	}
}
 
開發者ID:julianfalcionelli,項目名稱:SimpleRESTClientHandler,代碼行數:18,代碼來源:BaseMultipartJsonArrayRequest.java

示例8: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    if (mType == null && mJavaClass == null) return Response.error(new ParseError());
    try {
        String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        T parsedGSON = null;
        if (mType != null) {
            parsedGSON = mGson.fromJson(jsonString, mType);
        } else {
            parsedGSON = mGson.fromJson(jsonString, mJavaClass);
        }
        return Response.success(parsedGSON,
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JsonSyntaxException je) {
        return Response.error(new ParseError(je));
    }
}
 
開發者ID:yangweigbh,項目名稱:VolleyX,代碼行數:20,代碼來源:GsonRequest.java

示例9: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
/**
     * 數據返回
     */
    @Override
    protected Response<T> parseNetworkResponse(NetworkResponse response) {
        try {
            String strRue = new String(response.data, "UTF-8");
//            if (BuildConfig.DEBUG)
//                Log.d(TAG, xml);
            if (strRue.contains("error")) { //server返回錯誤
                ServerErrorResult serverError = mGson.fromJson(strRue,ServerErrorResult.class);
                Response.error(new MyErrorMessage(serverError.getStatus(),serverError.getMessage()));
            }
            return Response.success(mGson.fromJson(strRue,mClazz),HttpHeaderParser.parseCacheHeaders(response));
        } catch (Exception e) {
            e.printStackTrace();
            return Response.error(new ParseError(e));
        }
    }
 
開發者ID:yun2win,項目名稱:yun2win-sdk-android,代碼行數:20,代碼來源:MyRequest.java

示例10: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {

    try {
        Map<String, String> headers = response.headers;
        // TODO: 16/6/1 可以處理網絡返回頭信息

        String parsed = "";
        if (response.data != null && response.data.length > 0) {
            parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers, "utf-8"));
        }
        T map = gson.fromJson(parsed,
                new TypeToken<T>() {
                }.getType());

        return Response.success(map, HttpHeaderParser.parseCacheHeaders(response));
    } catch (Exception je) {
        return Response.error(new ParseError(je));
    }

}
 
開發者ID:jessie345,項目名稱:RealArchitecture,代碼行數:22,代碼來源:VolleyRequest.java

示例11: doParse

import com.android.volley.ParseError; //導入依賴的package包/類
/**
 * The real guts of parseNetworkResponse. Broken out for readability.
 */
private Response<Bitmap> doParse(NetworkResponse response) {
    Bitmap bitmap = null;
    if (response instanceof StreamBasedNetworkResponse) {
        InputStream bitmapStream = ((StreamBasedNetworkResponse) response).inputStream;
        if (bitmapStream != null) {
            //parse bitmap stream
            bitmap = doParseStreamSafe(bitmapStream, ((StreamBasedNetworkResponse) response).contentLength);
        } else {
            //parse bitmap bytes
            bitmap = doParseBytes(response.data);
        }
    } else {
        //parse bitmap bytes
        bitmap = doParseBytes(response.data);
    }

    if (bitmap == null) {
        return Response.error(new ParseError(response));
    } else {
        return Response.success(bitmap, null);
    }
}
 
開發者ID:HujiangTechnology,項目名稱:RestVolley,代碼行數:26,代碼來源:RVImageRequest.java

示例12: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {

	try {
		String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response
				.headers));
		JSONObject jsonObject = new JSONObject(resultStr);

		if (jsonObject.opt("status").equals("ok")) {
			JSONObject contentObject = jsonObject.optJSONObject("post");
			return Response.success(contentObject.optString("content"), HttpHeaderParser.parseCacheHeaders
					(response));
		} else {
			return Response.success("error", HttpHeaderParser.parseCacheHeaders(response));
		}

	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
開發者ID:niuzehai,項目名稱:Sxumiro_AndroidClient,代碼行數:22,代碼來源:Request4FreshNewsDetail.java

示例13: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    try {
        if (response != null && response.data != null && response.data.length > 0) {
            if (ClientUtils.isBasicType(type)) {
                return (Response<T>) Response.success(new String(response.data, "UTF-8"),
                        HttpHeaderParser.parseCacheHeaders(response));
            } else {
                return Response.success((T) ClientUtils.getJsonReader(type).
                        readValue(response.data), HttpHeaderParser.parseCacheHeaders(response));
            }
        } else {
            return Response.success(null, HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        logger.error("JSON parsing error", e);
        return Response.error(new ParseError(e));
    }
}
 
開發者ID:Erudika,項目名稱:para-client-android,代碼行數:21,代碼來源:ParaRequest.java

示例14: parseResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@NonNull
private Response<List<SearchEntry>> parseResponse(NetworkResponse response) {
    try {
        String html = new String(response.data, parseCharset(response.headers));
        Document document = Jsoup.parse(html);
        Elements elements = document.getElementsByClass("title-detail");
        List<SearchEntry> searches = new ArrayList<>();
        for (Element element : elements) {
            Element item = element.child(0);
            SearchEntry search = new SearchEntry();
            search.url = "http://m.guokr.com" + item.attr("href");
            search.content = item.html();
            search.datetime = element.child(1).child(1).attr("datetime");
            searches.add(search);
        }
        onParseResult(searches);
        return Response.success(searches, parseCacheHeaders(response));
    } catch (Exception e) {
        return Response.error(new ParseError(e));
    }
}
 
開發者ID:drunlin,項目名稱:guokr-android,代碼行數:22,代碼來源:SearchModelImpl.java

示例15: parseNetworkResponse

import com.android.volley.ParseError; //導入依賴的package包/類
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
	try {
		String jsonString =
				new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		Response<JSONArray> success = Response.success(new JSONArray(jsonString),
				HttpHeaderParser.parseCacheHeaders(response));
		if (mProcessor != null) {
			// do in background...
			mProcessor.asyncProcess(mContext, success.result);
		}
		return success;
	} catch (UnsupportedEncodingException e) {
		return Response.error(new ParseError(e));
	} catch (JSONException je) {
		return Response.error(new ParseError(je));
	} catch (Exception ex) {
		return Response.error(new VolleyError(ex));
	}
}
 
開發者ID:missmisslonely,項目名稱:fakeweibo,代碼行數:21,代碼來源:CatnutArrayRequest.java


注:本文中的com.android.volley.ParseError類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。