Java Code Examples for com.android.volley.toolbox.HttpHeaderParser#parseCharset()
The following examples show how to use
com.android.volley.toolbox.HttpHeaderParser#parseCharset() .
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: Request4FreshNewsDetail.java From JianDan with Apache License 2.0 | 6 votes |
@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 2
Source File: Request4Picture.java From JianDan with Apache License 2.0 | 6 votes |
@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: Request4PushComment.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 6 votes |
@Override protected Response<Boolean> parseNetworkResponse(NetworkResponse response) { try { String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject resultObj = new JSONObject(resultStr); int code = resultObj.optInt("code"); if (code == 0) { return Response.success(true, HttpHeaderParser.parseCacheHeaders(response)); } else { return Response.error(new VolleyError("错误码:" + code)); } } catch (Exception e) { e.printStackTrace(); return Response.error(new VolleyError(e)); } }
Example 4
Source File: Request4Picture.java From JianDan_OkHttp with Apache License 2.0 | 6 votes |
@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 5
Source File: GsonRequest.java From VolleyX with Apache License 2.0 | 6 votes |
@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 6
Source File: DeleteIDProfile.java From Saiy-PS with GNU Affero General Public License v3.0 | 5 votes |
/** * Used for debugging only to view verbose error information * * @param error the {@link VolleyError} */ private void verboseError(@NonNull final VolleyError error) { final NetworkResponse response = error.networkResponse; if (response != null && error instanceof ServerError) { try { final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); MyLog.i(CLS_NAME, "result: " + result); } catch (final UnsupportedEncodingException e) { e.printStackTrace(); } } }
Example 7
Source File: DeleteRequest.java From swaggy-jenkins with MIT License | 5 votes |
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); }
Example 8
Source File: PutRequest.java From swaggy-jenkins with MIT License | 5 votes |
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); }
Example 9
Source File: PostRequest.java From swaggy-jenkins with MIT License | 5 votes |
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); }
Example 10
Source File: MultipartRequest.java From android-common-utils with Apache License 2.0 | 5 votes |
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); }
Example 11
Source File: FetchIDProfile.java From Saiy-PS with GNU Affero General Public License v3.0 | 5 votes |
/** * Used for debugging only to view verbose error information * * @param error the {@link VolleyError} */ private void verboseError(@NonNull final VolleyError error) { final NetworkResponse response = error.networkResponse; if (response != null && error instanceof ServerError) { try { final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); MyLog.i(CLS_NAME, "result: " + result); } catch (final UnsupportedEncodingException e) { e.printStackTrace(); } } }
Example 12
Source File: ListIDProfiles.java From Saiy-PS with GNU Affero General Public License v3.0 | 5 votes |
/** * Used for debugging only to view verbose error information * * @param error the {@link VolleyError} */ private void verboseError(@NonNull final VolleyError error) { final NetworkResponse response = error.networkResponse; if (response != null && error instanceof ServerError) { try { final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); MyLog.i(CLS_NAME, "result: " + result); } catch (final UnsupportedEncodingException e) { e.printStackTrace(); } } }
Example 13
Source File: TransientUsersFragment.java From catnut with MIT License | 5 votes |
private Response<List<TransientUser>> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject result = new JSONObject(jsonString); // set next_cursor mNext_cursor = result.optInt(User.next_cursor); mTotal_number = result.optInt(User.total_number); JSONArray array = result.optJSONArray(User.MULTIPLE); if (array != null) { List<TransientUser> users = new ArrayList<TransientUser>(array.length()); for (int i = 0; i < array.length(); i++) { users.add(TransientUser.convert(array.optJSONObject(i))); } return Response.success(users, HttpHeaderParser.parseCacheHeaders(response)); } else { throw new RuntimeException("no users found!"); } } 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 ParseError(ex)); } }
Example 14
Source File: CustomObjectRequest.java From qBittorrent-Controller with MIT License | 5 votes |
@Override protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { // since we don't know which of the two underlying network vehicles // will Volley use, we have to handle and store session cookies manually //MyApp.get().checkSessionCookie(response.headers); this.headers = response.headers; // Log.d("Debug", "Response headers: " + response.headers); //return super.parseNetworkResponse(response); try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET)); Log.d("Debug", "jsonString: " + jsonString); JSONObject jsonResponse = new JSONObject(jsonString); jsonResponse.put("headers", new JSONObject(response.headers)); return Response.success(jsonResponse, HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JSONException je) { return Response.error(new ParseError(je)); } }
Example 15
Source File: Request4FreshNews.java From JianDan with Apache License 2.0 | 5 votes |
@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 16
Source File: GsonRequest.java From Rocko-Android-Demos with Apache License 2.0 | 5 votes |
@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 17
Source File: Request4CommentCounts.java From JianDan with Apache License 2.0 | 5 votes |
@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 18
Source File: Request4Vote.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
@Override protected Response<Vote> parseNetworkResponse(NetworkResponse response) { try { String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success(Vote.getInstance(jsonStr), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }
Example 19
Source File: Request4Video.java From JianDan_OkHttp with Apache License 2.0 | 4 votes |
@Override protected Response<ArrayList<Video>> parseNetworkResponse(NetworkResponse response) { try { String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject jsonObject = new JSONObject(jsonStr); if ("ok".equals(jsonObject.optString("status"))) { JSONArray commentsArray = jsonObject.optJSONArray("comments"); ArrayList<Video> videos = new ArrayList<>(); for (int i = 0; i < commentsArray.length(); i++) { JSONObject commentObject = commentsArray.getJSONObject(i); JSONObject videoObject = commentObject.optJSONArray("videos").optJSONObject(0); if (videoObject != null) { Video video = new Video(); video.setTitle(videoObject.optString("title")); String videoSource = videoObject.optString("video_source"); video.setComment_ID(commentObject.optString("comment_ID")); video.setVote_positive(commentObject.optString("vote_positive")); video.setVote_negative(commentObject.optString("vote_negative")); video.setVideo_source(videoSource); if (videoSource.equals("youku")) { video.setUrl(videoObject.optString("link")); video.setDesc(videoObject.optString("description")); video.setImgUrl(videoObject.optString("thumbnail")); video.setImgUrl4Big(videoObject.optString("thumbnail_v2")); } else if (videoSource.equals("56")) { video.setUrl(videoObject.optString("url")); video.setDesc(videoObject.optString("desc")); video.setImgUrl4Big(videoObject.optString("img")); video.setImgUrl(videoObject.optString("mimg")); } else if (videoSource.equals("tudou")) { video.setUrl(videoObject.optString("playUrl")); video.setImgUrl(videoObject.optString("picUrl")); video.setImgUrl4Big(videoObject.optString("picUrl")); video.setDesc(videoObject.optString("description")); } videos.add(video); } } return Response.success(videos, HttpHeaderParser.parseCacheHeaders(response)); } else { return Response.success(new ArrayList<Video>(), HttpHeaderParser.parseCacheHeaders(response)); } } catch (Exception e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }
Example 20
Source File: Request4FreshNewsCommentList.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 4 votes |
@Override protected Response<ArrayList<Comment4FreshNews>> parseNetworkResponse(NetworkResponse response) { try { String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject resultObj = new JSONObject(resultStr); String status = resultObj.optString("status"); if (status.equals("ok")) { String commentsStr = resultObj.optJSONObject("post").optJSONArray("comments") .toString(); int id = resultObj.optJSONObject("post").optInt("id"); mCallBack.loadFinish(Integer.toString(id)); ArrayList<Comment4FreshNews> comment4FreshNewses = (ArrayList<Comment4FreshNews>) JSONParser.toObject(commentsStr, new TypeToken<ArrayList<Comment4FreshNews>>() { }.getType()); Pattern pattern = Pattern.compile("\\d{7}"); for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) { Matcher matcher = pattern.matcher(comment4FreshNews.getContent()); boolean isHas7Num = matcher.find(); boolean isHasCommentStr = comment4FreshNews.getContent().contains("#comment-"); //有回复 if (isHas7Num && isHasCommentStr || comment4FreshNews.getParentId() != 0) { ArrayList<Comment4FreshNews> tempComments = new ArrayList<>(); int parentId = getParentId(comment4FreshNews.getContent()); comment4FreshNews.setParentId(parentId); getParenFreshNews(tempComments, comment4FreshNewses, parentId); Collections.reverse(tempComments); comment4FreshNews.setParentComments(tempComments); comment4FreshNews.setFloorNum(tempComments.size() + 1); comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent())); } else { comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent())); } } Logger.d("" + comment4FreshNewses); return Response.success(comment4FreshNewses, HttpHeaderParser .parseCacheHeaders(response)); } else { return Response.error(new ParseError(new Exception("request failed"))); } } catch (Exception e) { e.printStackTrace(); return Response.error(new ParseError(e)); } }