没有收到完整的JSON响应 [英] Not receiving the complete JSON response

查看:115
本文介绍了没有收到完整的JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Volley向API发出GET请求:

I'm using Volley to make a GET request to an API:

    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信息:

The expected JSON object response is big (could be upto 500 KB). I'm unable to see the complete response in my logs. Only the first 50 lines or so are displayed. I'm also getting BasicNetwork.logSlowRequests info:

BasicNetwork.logSlowRequests:request =< []

BasicNetwork.logSlowRequests: HTTP response for request=<[ ]

这意味着请求耗时超过3000毫秒.

which means the request is taking more than 3000 ms.

尝试过的事情:

我已经在电话的开发人员选项"中将记录器缓冲区的大小增加到1M.

I've increased the logger buffer sizes to 1M in Developers Options in the phone.

可能是什么原因?响应很大时是否按块发送? 如果是这样,如何加入他们以分析完整的响应?

What could be the reason? Is the response sent in chunks when it's big? If so, how to join them to parse the full response?

推荐答案

如果日志很大,则日志不会显示完整的字符串,请尝试写入磁盘上的文件并检查其是否完整.

Log does not show the complete string if it very big ,try writing to a file on disk and check it should be complete.

您还可以使用此方法来打印完整的日志:

Also you can use this method to print complete log:

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);
}

这篇关于没有收到完整的JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆