com.android.volley.ParseError Java Examples

The following examples show how to use com.android.volley.ParseError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestSingletonFactory.java    From Netease with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onErrorResponse(VolleyError error) {
    error.printStackTrace();
    Log.d("RVA", "error:" + error);

    int errorCode = 0;
    if (error instanceof TimeoutError) {
        errorCode = -7;
    } else if (error instanceof NoConnectionError) {
        errorCode = -1;
    } else if (error instanceof AuthFailureError) {
        errorCode = -6;
    } else if (error instanceof ServerError) {
        errorCode = 0;
    } else if (error instanceof NetworkError) {
        errorCode = -1;
    } else if (error instanceof ParseError) {
        errorCode = -8;
    }
    Toast.makeText(contextHold, ErrorCode.errorCodeMap.get(errorCode), Toast.LENGTH_SHORT).show();
}
 
Example #2
Source File: Request4Picture.java    From JianDan_OkHttpWithVolley with Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example #3
Source File: Request4Picture.java    From JianDan with Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example #4
Source File: Request4Joke.java    From JianDan_OkHttp with Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Joke>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		return Response.success((ArrayList<Joke>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Joke>>() {
				}.getType()), HttpHeaderParser.parseCacheHeaders(response));

	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example #5
Source File: Request4FreshNewsDetail.java    From JianDan with Apache License 2.0 6 votes vote down vote up
@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));
	}
}
 
Example #6
Source File: RVImageRequest.java    From RestVolley with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #7
Source File: Request4FreshNewsDetail.java    From JianDan_OkHttp with Apache License 2.0 6 votes vote down vote up
@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));
	}
}
 
Example #8
Source File: GsonRequest.java    From VolleyX with Apache License 2.0 6 votes vote down vote up
@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));
    }
}
 
Example #9
Source File: Request4Picture.java    From JianDan_OkHttp with Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
		return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example #10
Source File: Request4Joke.java    From JianDan with Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Joke>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		return Response.success((ArrayList<Joke>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Joke>>() {
				}.getType()), HttpHeaderParser.parseCacheHeaders(response));

	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example #11
Source File: Request4Joke.java    From JianDan_OkHttpWithVolley with Apache License 2.0 6 votes vote down vote up
@Override
protected Response<ArrayList<Joke>> parseNetworkResponse(NetworkResponse response) {

	try {
		String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();

		return Response.success((ArrayList<Joke>) JSONParser.toObject(jsonStr,
				new TypeToken<ArrayList<Joke>>() {
				}.getType()), HttpHeaderParser.parseCacheHeaders(response));

	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example #12
Source File: JsonArrayRequest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example #13
Source File: JsonObjectRequest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example #14
Source File: Request4CommentCounts.java    From JianDan_OkHttp with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));

        JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response");
        String[] comment_IDs = getUrl().split("\\=")[1].split("\\,");
        ArrayList<CommentNumber> commentNumbers = new ArrayList<>();

        for (String comment_ID : comment_IDs) {

            if (!jsonObject.isNull(comment_ID)) {
                CommentNumber commentNumber = new CommentNumber();
                commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS));
                commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID));
                commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY));
                commentNumbers.add(commentNumber);
            } else {
                //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据
                commentNumbers.add(new CommentNumber("0", "0", 0));
            }
        }

        return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response));

    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example #15
Source File: ImageRequest.java    From TitanjumNote with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    // Serialize all decode on a global lock to reduce concurrent heap usage.
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            VolleyLog.e("Caught OOM for %d byte image, url=%s",
                    response.data.length, getUrl());
            return Response.error(new ParseError(e));
        }
    }
}
 
Example #16
Source File: ImageRequest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    // Serialize all decode on a global lock to reduce concurrent heap usage.
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            VolleyLog.e("Caught OOM for %d byte image, url=%s", response.data.length, getUrl());
            return Response.error(new ParseError(e));
        }
    }
}
 
Example #17
Source File: JsonObjectRequest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example #18
Source File: SyncAdapter.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
private static boolean didServerReturnNull(ExecutionException e) {
    if (e.getCause() instanceof ParseError) {
        ParseError cause = (ParseError) e.getCause();
        if (cause.getCause() instanceof JSONException) {
            JSONException causeCause = (JSONException) cause.getCause();
            if (causeCause.getMessage().contains("Value null of")) {
                return true;
            }
        }
    }
    return false;
}
 
Example #19
Source File: JsonArrayRequest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example #20
Source File: ImageRequest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    // Serialize all decode on a global lock to reduce concurrent heap usage.
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            VolleyLog.e("Caught OOM for %d byte image, url=%s", response.data.length, getUrl());
            return Response.error(new ParseError(e));
        }
    }
}
 
Example #21
Source File: Request4FreshNews.java    From JianDan_OkHttp with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<ArrayList<FreshNews>> parseNetworkResponse(NetworkResponse response) {

	try {
		String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		JSONObject resultObj = new JSONObject(resultStr);
		JSONArray postsArray = resultObj.optJSONArray("posts");
		return Response.success(FreshNews.parse(postsArray), HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example #22
Source File: ImageRequest.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<Bitmap> parseNetworkResponse(NetworkResponse response) {
    // Serialize all decode on a global lock to reduce concurrent heap usage.
    synchronized (sDecodeLock) {
        try {
            return doParse(response);
        } catch (OutOfMemoryError e) {
            VolleyLog.e("Caught OOM for %d byte image, url=%s", response.data.length, getUrl());
            return Response.error(new ParseError(e));
        }
    }
}
 
Example #23
Source File: JsonArrayRequest.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example #24
Source File: JsonObjectRequest.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString =
            new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        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));
    }
}
 
Example #25
Source File: GsonRequest.java    From ExRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers));
        return Response.success(mGson.fromJson(jsonString, mClass),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    }
}
 
Example #26
Source File: Request4CommentCounts.java    From JianDan with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));

        JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response");
        String[] comment_IDs = getUrl().split("\\=")[1].split("\\,");
        ArrayList<CommentNumber> commentNumbers = new ArrayList<>();

        for (String comment_ID : comment_IDs) {

            if (!jsonObject.isNull(comment_ID)) {
                CommentNumber commentNumber = new CommentNumber();
                commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS));
                commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID));
                commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY));
                commentNumbers.add(commentNumber);
            } else {
                //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据
                commentNumbers.add(new CommentNumber("0", "0", 0));
            }
        }

        return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response));

    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example #27
Source File: Request4FreshNews.java    From JianDan with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<ArrayList<FreshNews>> parseNetworkResponse(NetworkResponse response) {

	try {
		String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		JSONObject resultObj = new JSONObject(resultStr);
		JSONArray postsArray = resultObj.optJSONArray("posts");
		return Response.success(FreshNews.parse(postsArray), HttpHeaderParser.parseCacheHeaders(response));
	} catch (Exception e) {
		e.printStackTrace();
		return Response.error(new ParseError(e));
	}
}
 
Example #28
Source File: GsonRequest.java    From Rocko-Android-Demos with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        if (mTypeToken == null)
            return Response.success(mGson.fromJson(jsonString, mClass),
                    HttpHeaderParser.parseCacheHeaders(response));
        else
            return (Response<T>) Response.success(mGson.fromJson(jsonString, mTypeToken.getType()),
                    HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    }
}
 
Example #29
Source File: StringRequestGet.java    From renrenpay-android with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
    try {
        String jsonString = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
        return Response.success(jsonString, HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JSONException je) {
        return Response.error(new ParseError(je));
    }
}
 
Example #30
Source File: Request4CommentCounts.java    From JianDan_OkHttpWithVolley with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));

        JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response");
        String[] comment_IDs = getUrl().split("\\=")[1].split("\\,");
        ArrayList<CommentNumber> commentNumbers = new ArrayList<>();

        for (String comment_ID : comment_IDs) {

            if (!jsonObject.isNull(comment_ID)) {
                CommentNumber commentNumber = new CommentNumber();
                commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS));
                commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID));
                commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY));
                commentNumbers.add(commentNumber);
            } else {
                //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据
                commentNumbers.add(new CommentNumber("0", "0", 0));
            }
        }

        return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response));

    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}