Android Volley Library不会返回整个响应数据 [英] Android Volley Library doen't return whole response data

查看:154
本文介绍了Android Volley Library不会返回整个响应数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Volley库不会返回整个响应数据.它仅返回部分响应数据.我正在打电话给drupal服务.下面是我的代码.

Volley library doesn't return whole response data. It only return the part of the response data. I am calling drupal services. Below is my code for it.

public void BoardRoomRequest() {
        pdialog = new ProgressDialog(BoardRoom.this);
        pdialog.setTitle("Please wait....");
        String url = Global_Application.url + "views/boardroom";
        Log.d("url========", url);
        Map<String, String> params = new HashMap<String, String>();
        StringRequest req = new StringRequest(Request.Method.GET,
                getApplicationContext(), url, params,
                new Response.Listener<String>() {

                    @Override
                    public void onResponse(String response) {
                        // TODO Auto-generated method stub
                        Log.d("Response", response);

                        pdialog.dismiss();
                    }
                }, new ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // TODO Auto-generated method stub
                        Log.d("Error.Response", error.toString());
                        pdialog.dismiss();
                    }
                });

        queue.add(req);
        pdialog.show();
    }    

推荐答案

Volley!并不是问题,这是logcat用于显示有限大小数据的问题(局限性).(我假设您正在从代码中读取logcat中的响应)

It's not the problem with Volley!, it's the problem(limitation) of logcat for displaying limited size of data. (I'm assuming you are reading the response in logcat from your code)

如果您使用的是日食,这是解决方案

if you are using eclipse here is the solution

 public void BoardRoomRequest() {
            pdialog = new ProgressDialog(BoardRoom.this);
            pdialog.setTitle("Please wait....");
            String url = Global_Application.url + "views/boardroom";
            Log.d("url========", url);
            Map<String, String> params = new HashMap<String, String>();
            StringRequest req = new StringRequest(Request.Method.GET,
                    getApplicationContext(), url, params,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            // TODO Auto-generated method stub

                       // Log.d("Response", response);  //can't display more data

                    //=========================
                    longInfo(response); //solution for displaying more data in logcat
                    //=========================

                            pdialog.dismiss();
                        }
                    }, new ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
                            Log.d("Error.Response", error.toString());
                            pdialog.dismiss();
                        }
                    });

            queue.add(req);
            pdialog.show();
        }   

public void longInfo(String str) {
            if(str.length() > 4000) {
                Log.i("",str.substring(0, 4000));
                longInfo(str.substring(4000));
            } else
                Log.i("",str);
        } 

注意::$ adb logcat -g环形缓冲区为64Kb(已消耗63Kb),最大条目为4096b,最大有效负载为4076b

Note: $ adb logcat -g ring buffer is 64Kb (63Kb consumed), max entry is 4096b, max payload is 4076b

LogCat很大程度上取决于设备.不同的手机之间,尺寸和不良字符的处理方式也不同.

LogCat is very much device dependent. The size and also the handling of bad character differs between different handsets.

也请尝试以下操作:

     import java.util.*;

        class Test
        {
        public static void main(String[] args)
        {
        System.out.println(Arrays.toString(
        "Thequickbrownfoxjumps".split("(?<=\\G.{4})")
        ));
        }
        }

output: [Theq, uick, brow, nfox, jump, s]

这篇关于Android Volley Library不会返回整个响应数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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