@Override public void doAfter(JSONArray jsonArray) { flProxy.setVisibility(View.GONE); if (jsonArray != null) { try { Gson gson = new Gson(); Response response = gson.fromJson(jsonArray.getJSONObject(0).toString(), Response.class); android.support.design.widget.Snackbar.make( findViewById(R.id.cl_container), response.getMessage(), android.support.design.widget.Snackbar.LENGTH_LONG) .show(); if (response.getStatus()) { etSubject.setText(""); etMessage.setText(""); } } catch (JSONException e) { e.printStackTrace(); } } else { android.support.design.widget.Snackbar.make( findViewById(R.id.cl_container), "Falhou, tente novamente.", android.support.design.widget.Snackbar.LENGTH_LONG) .show(); } }
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { try { String ret = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success(ret, HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception E) { return Response.error(new ParseError(E)); } }
/** * 这里开始解析数据 * * @param response Response from the network * @return */ @Override protected Response<String> parseNetworkResponse(NetworkResponse response) { try { String mString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success(mString, HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } }
@Override protected Response<Tick5Response> parseNetworkResponse(NetworkResponse response) { try { return Response.success( mGson.fromJson(new String(response.data, "UTF-8"), Tick5Response.class), getCacheEntry()); } catch (Exception e) { Log.e("TICK5 REQUEST", e.getMessage()); return Response.error(new VolleyError("Uanble to parse response: " + e.getMessage())); } }
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) { try { String je = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success(new JSONArray(je), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException var3) { return Response.error(new ParseError(var3)); } catch (JSONException var4) { return Response.error(new ParseError(var4)); } }
@Override protected Response<JsonObject> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject(); return Response.success(jsonObject, HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } }
@Override protected Response<T> parseNetworkResponse(NetworkResponse response) { try { String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success( gson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JsonSyntaxException e) { return Response.error(new ParseError(e)); } }
@Override protected Response<T> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success( Mapper.objectOrThrow(jsonString, responseType), HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception e) { return Response.error(new ParseError(e)); } }
@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)); } }
@Override protected Response<List<Project>> parseNetworkResponse(NetworkResponse response) { try { String jsonArrayString = new String(response.data, HttpHeaderParser.parseCharset(response.headers, "utf-8")); JSONArray jsonArray = new JSONArray(jsonArrayString); List<Project> projects = Project.fromJSONArray(jsonArray); return Response.success(projects, HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JSONException e) { return Response.error(new ParseError(e)); } }
@Override protected Response<T> parseNetworkResponse(NetworkResponse response) { try { Logger.d("YbbHttpRequest", requestUrl() + "?" + WebUtils.buildQuery(GetParameters())); String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); Logger.d("YbbHttpRequest", StringUtils.unicodeToChinese(json)); return Response.success( mGson.fromJson(json, getResponseClass()), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JsonSyntaxException e) { return Response.error(new ParseError(e)); } }
@Override // 解析返回的数据 protected Response<String> parseNetworkResponse(NetworkResponse response) { byte[] data = response.data; Log.d("test", "url = " + getUrl() + ",response = " + new String(data)); try { String model = new String(data); return Response.success(model, HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception e) { // 解析json出错 e.printStackTrace(); return Response.error(new VolleyError("服务器错误")); } }
private void verifyResize( NetworkResponse networkResponse, int maxWidth, int maxHeight, int expectedWidth, int expectedHeight) { ImageRequest request = new ImageRequest("", null, maxWidth, maxHeight, Config.RGB_565, null); Response<Bitmap> response = request.parseNetworkResponse(networkResponse); assertNotNull(response); assertTrue(response.isSuccess()); Bitmap bitmap = response.result; assertNotNull(bitmap); assertEquals(expectedWidth, bitmap.getWidth()); assertEquals(expectedHeight, bitmap.getHeight()); }
@Override protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) { try { String js = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); Log.i("APP", js); return (Response.success(new JSONArray(js), HttpHeaderParser.parseCacheHeaders(response))); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); /*if(e.getMessage().contains("{\"id\":\"not_found\"}")){ HashMap<String,String> jsErr = new HashMap<String,String>(); jsErr.put("id","not_found"); HashMap<String,String> nulo = new HashMap<String,String>(); //nulo.put("0","0"); ArrayList<HashMap> ja = new ArrayList<HashMap>(); ja.add(jsErr); //ja.add(nulo); return(Response.success(new JSONArray(ja), HttpHeaderParser.parseCacheHeaders(response))); }*/ } return null; }
@Override protected Response parseNetworkResponse(NetworkResponse response) { if (response.statusCode != 200) { return Response.error(new VolleyError("failer")); } else { try { String content = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); L.e(content); T t = JSON.parseObject(content, clazz); return Response.success(t, HttpHeaderParser.parseCacheHeaders(response)); } catch (Exception e) { e.printStackTrace(); return Response.error(new VolleyError("failer")); } } }
protected Response<JSONObject> parseNetworkResponse(NetworkResponse paramNetworkResponse) { try { Response localResponse = Response.success( new JSONObject( new String( paramNetworkResponse.data, HttpHeaderParser.parseCharset(paramNetworkResponse.headers))), HttpHeaderParser.parseCacheHeaders(paramNetworkResponse)); return localResponse; } catch (UnsupportedEncodingException localUnsupportedEncodingException) { return Response.error(new ParseError(localUnsupportedEncodingException)); } catch (JSONException localJSONException) { return Response.error(new ParseError(localJSONException)); } }
@Override protected Response<XmlPullParser> parseNetworkResponse(NetworkResponse networkResponse) { String xmlString = null; try { xmlString = new String(networkResponse.data, HttpHeaderParser.parseCharset(networkResponse.headers)); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser xmlPullParser = factory.newPullParser(); xmlPullParser.setInput(new StringReader(xmlString)); return Response.success(xmlPullParser, HttpHeaderParser.parseCacheHeaders(networkResponse)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError()); } catch (XmlPullParserException e) { return Response.error(new ParseError()); } }
@Override protected Response<List<Game>> parseNetworkResponse(NetworkResponse response) { try { List<Game> games = new ArrayList<>(); JSONArray json = new JSONArray(new String(response.data, HttpHeaderParser.parseCharset(response.headers))); for (int i = 0; i < json.length(); i++) { games.add(Game.fromJSON(json.getJSONObject(i))); } return Response.success(games, HttpHeaderParser.parseCacheHeaders(response)); } catch (JSONException e) { return Response.error(new ParseError(e)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } }
@Override protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { Log.d(TAG, "$$$ parseNetworkResponse"); try { Log.d(TAG, " status Code " + response.statusCode); initDevicePairResponseData(response.statusCode, response.headers, new String(response.data)); 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)); } }
@Override protected Response<Workitem> parseNetworkResponse(NetworkResponse networkResponse) { try { String json = new String( networkResponse.data, HttpHeaderParser.parseCharset(networkResponse.headers, "utf-8")); Workitem workitem = Workitem.fromJSON(new JSONArray(json).getJSONObject(0)); return Response.success(workitem, HttpHeaderParser.parseCacheHeaders(networkResponse)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (ParseException e) { return Response.error(new ParseError(e)); } catch (JSONException e) { return Response.error(new ParseError(e)); } }
/** * Convert response to UTF8 charset, two solution added, only one simple should suffice * * @param response - network responce to be converted * @return converted responce */ @Override protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { try { // simple fix String jsonString = new String(response.data, "UTF-8"); // harder fix // response.headers.put(HTTP.CONTENT_TYPE,response.headers.get("content-type")); // 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)); } }
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)); }
@Override protected Response<NetworkResponse> parseNetworkResponse(NetworkResponse response) { int statusCode = response.statusCode; Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response); Log.i(TAG, "status code: " + statusCode); return Response.success(response, entry); }
// parse the gzip response using a GZIPInputStream @Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String output = ""; try { GZIPInputStream gStream = new GZIPInputStream(new ByteArrayInputStream(response.data)); InputStreamReader reader = new InputStreamReader(gStream); BufferedReader in = new BufferedReader(reader); String read; while ((read = in.readLine()) != null) { output += read; } reader.close(); in.close(); gStream.close(); } catch (IOException e) { return Response.error(new ParseError()); } return Response.success(output, HttpHeaderParser.parseCacheHeaders(response)); }
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { // TODO Auto-generated method stub 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)); }
@Override protected Response<ResponseDTO> parseNetworkResponse(NetworkResponse response) { ResponseDTO dto = new ResponseDTO(); try { Gson gson = new Gson(); String resp = new String(response.data); Log.i(LOG, "response string length returned: " + getSize(resp.length())); try { dto = gson.fromJson(resp, ResponseDTO.class); if (dto != null) { return Response.success(dto, HttpHeaderParser.parseCacheHeaders(response)); } } catch (Exception e) { // ignore, it's a zipped response } InputStream is = new ByteArrayInputStream(response.data); ZipInputStream zis = new ZipInputStream(is); @SuppressWarnings("unused") ZipEntry entry; ByteArrayBuffer bab = new ByteArrayBuffer(2048); while ((entry = zis.getNextEntry()) != null) { int size = 0; byte[] buffer = new byte[2048]; while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bab.append(buffer, 0, size); } resp = new String(bab.toByteArray()); dto = gson.fromJson(resp, ResponseDTO.class); } } catch (Exception e) { VolleyError ve = new VolleyError("Exception parsing server data", e); errorListener.onErrorResponse(ve); Log.e(LOG, "Unable to complete request: " + dto.getMessage(), e); return Response.error(new VolleyError(dto.getMessage())); } end = System.currentTimeMillis(); Log.e(LOG, "#### comms elapsed time in seconds: " + getElapsed(start, end)); return Response.success(dto, HttpHeaderParser.parseCacheHeaders(response)); }
@SuppressWarnings("unchecked") @Override protected Response<T> parseNetworkResponse(NetworkResponse response) { String json; try { json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); if (Configuration.isShowNetworkJson()) Log.e("result", json); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } Type objectType; if (mClass != null) { objectType = type(parentClass, mClass); } else { objectType = parentClass; } return (Response<T>) Response.success( mGson.fromJson(json, objectType), HttpHeaderParser.parseCacheHeaders(response)); }
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { // TODO Auto-generated method stub try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); Pattern pattern = Pattern.compile("Set-Cookie.*?;"); Matcher m = pattern.matcher(response.headers.toString()); if (m.find()) { cookie = m.group(); // L.e("LOG","cookie from server "+ cookie); } return Response.success(jsonString, HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } }
@Override protected Response<T> parseNetworkResponse(NetworkResponse response) { try { String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); JSONObject obj = new JSONObject(json); if (obj.getString("status").equalsIgnoreCase("OK")) { Log.v(MainActivity.TAG, "Request is SUCCESS !!"); return Response.success( gson.fromJson(obj.getJSONObject(clazz.getSimpleName().toLowerCase()).toString(), clazz), HttpHeaderParser.parseCacheHeaders(response)); } else { return Response.error(new VolleyError("Failed or Unexpected response message !!")); } } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JsonSyntaxException e) { return Response.error(new ParseError(e)); } catch (JSONException e) { return Response.error(new ParseError(e)); } }
@Override protected Response<TwitterSearchResponse> parseNetworkResponse(NetworkResponse response) { // 1 second delay doArtificialDelay(); try { // get string response String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); // Parse string response with Gson TwitterSearchResponse twitterSearchResponse = gson.fromJson(json, TwitterSearchResponse.class); // process tweets if (twitterSearchResponse != null && tweetsResultProcessor != null) { tweetsResultProcessor.processTweets(twitterSearchResponse.getStatuses()); } return Response.success(twitterSearchResponse, HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } }