@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;
  }
Пример #2
0
 /**
  * 这里开始解析数据
  *
  * @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));
   }
 }
Пример #3
0
 @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));
   }
 }
Пример #4
0
 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));
 }
 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));
   }
 }
Пример #6
0
 @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<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<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));
   }
 }
Пример #9
0
 @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));
   }
 }
Пример #10
0
 @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));
   }
 }
Пример #11
0
 @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));
   }
 }
Пример #12
0
 @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));
   }
 }
Пример #13
0
 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<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));
   }
 }
Пример #15
0
 @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());
   }
 }
Пример #16
0
 @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"));
     }
   }
 }
Пример #17
0
  @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));
    }
  }
Пример #18
0
 @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));
   }
 }
Пример #19
0
 @Override
 protected Response<T> parseNetworkResponse(NetworkResponse response) {
   T t = null;
   try {
     String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
     Log.w("aaaaaaaaaaaaaaaa", "========JSON=======" + json);
     t = JSON.parseObject(json, clz);
     // 非空判断并且符合JSON格式
     /*
      * if (!TextUtils.isEmpty(json) && json.matches("^\\{.*\\}$")) { t =
      * JSON.parseObject(json, clz); }
      */
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   }
   // 得到解析的缓存头部信息
   return Response.success(t, HttpHeaderParser.parseCacheHeaders(response));
 }
Пример #20
0
  @Override
  protected Response<BaseResponse> parseNetworkResponse(NetworkResponse response) {

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

      /*  if (BuildConfig.DEBUG)
                      Log.d(TAG,"respone:"+jsonString);
      */

      BaseResponse baseResponse = parseJson(jsonString);
      return Response.success(baseResponse, HttpHeaderParser.parseCacheHeaders(response));

    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }

    return null;
  }
Пример #21
0
  @Override
  protected String getResponseString(NetworkResponse response) throws UnsupportedEncodingException {
    String responseString = null;
    String charset = HttpHeaderParser.parseCharset(response.headers);

    if (isGzipped(response)) {
      try {
        byte[] data = decompressResponse(response.data);
        responseString = new String(data, "utf-8");
      } catch (IOException e) {
        // it seems that result is not GZIP
      }
    }

    if (responseString == null) {
      responseString = new String(response.data, "utf-8");
    }

    return responseString;
  }
  @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));
    }
  }
Пример #23
0
 @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));
   }
 }
Пример #24
0
  @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));
  }
Пример #25
0
  @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));
    }
  }
  @Override
  protected Response<T> parseNetworkResponse(NetworkResponse response) {

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

      String result = new String(response.data, "UTF8");
      // result = URLDecoder.decode(result, "UTF8");
      // result=result.replace("\"", "");
      LogUtil.d(TAG, result); // 编码转换
      // Log.d(URLDecoder.decode("123abc\u8ba2\u5355\u5df2\u53d6\u6d88\u6216\u6b63\u5728\u53d6\u6d88\u4e2d",
      // "UTF-8"));

      return Response.success(
          JSON.parseObject(jsonString, mClass), HttpHeaderParser.parseCacheHeaders(response));
      // return Response.success(JSON.parseObject(jsonString,
      // mClass),HttpHeaderParser.parseIgnoreCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
      LogUtil.d(TAG, "error-7-8");
      return Response.error(new ParseError(e));
    }
  }
Пример #27
0
  @Override
  protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
    JSONArray replyJSONArray = new JSONArray();
    try {
      String jsonString =
          new String(
              response.data, HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));

      Object json = new JSONTokener(jsonString).nextValue();
      if (json instanceof JSONObject) {
        replyJSONArray.put(json);
      } else if (json instanceof JSONArray) {
        replyJSONArray = (JSONArray) json;
      }

    } catch (UnsupportedEncodingException e) {
      return Response.error(new ParseError(e));
    } catch (JSONException je) {
      return Response.error(new ParseError(je));
    }

    return Response.success(replyJSONArray, HttpHeaderParser.parseCacheHeaders(response));
  }