我正在使用 Volley 向 API 发出 GET 请求:
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("RESPONSE",response);
//this method parses the JSON response and fills it into a custom ArrayList
parseResponse(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("Sorry", "unable to get the response!");
}
});
预期的 JSON 对象响应很大(可能高达 500 KB)。 我无法在日志中看到完整的响应。仅显示前 50 行左右。我还收到 BasicNetwork.logSlowRequests
信息:
BasicNetwork.logSlowRequests: HTTP response for request=<[ ]
这意味着请求花费的时间超过 3000 毫秒。
尝试过的事情:
我已在手机的开发者选项中将记录器缓冲区大小增加到 1M。
可能是什么原因?当响应很大时是否会分块发送? 如果是这样,如何加入他们来解析完整的响应?
最佳答案
如果日志非常大,则日志不会显示完整的字符串,请尝试写入磁盘上的文件并检查它是否完整。
您也可以使用此方法打印完整的日志:
public static void longInfo(String str) {
if(str.length() > 4000) {
Log.i(TAG, str.substring(0, 4000));
longInfo(str.substring(4000));
} else
Log.i(TAG, str);
}
关于android - 未收到完整的 JSON 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546209/