使用JsonArrayRequest
调用Get方法时,得到的响应为空。
我尝试了请求中的OnResponse
和parseNetworkResponse
覆盖方法,但响应仍然为空。
String url = "http://myUrl";
RequestQueue requestQueue = Volley.newRequestQueue(mContext);
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null , new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.i("TAG",response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("on Error Response", error.toString());
}
})
{
@Override
public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
return headers;
}
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
int statusCode = response.statusCode;
switch (statusCode) {
case 200:
Log.i("TAG1", response.toString());
}
return null;
}
};
requestQueue.add(jsonArrayRequest);
我希望得到一个包含三个json对象的json数组
我也使用了这个:
return Response.success(response, HttpHeaderParser.parseCacheHeaders(response));
仍然响应为空。