在logcat监视器中获取完整的响应日志?

时间:2016-08-19 13:05:25

标签: android json android-studio response android-logcat

来自服务器的响应太长。所以我无法在android studio的logcat监视器中看到完整的响应。

有没有办法获得响应的完整logcat?

2 个答案:

答案 0 :(得分:1)

为此,您应该使用调试点。您可以获得完整的响应,并可以逐步执行代码。有关更多信息,请访问以下网站:

https://developer.android.com/studio/debug/index.html

答案 1 :(得分:0)

为此创建自定义类。在代码中使用它的重要方法是@pctroll的splitAndLog。

  public class Utils {
        /**
         * Divides a string into chunks of a given character size.
         * 
         * @param text                  String text to be sliced
         * @param sliceSize             int Number of characters
         * @return  ArrayList<String>   Chunks of strings
         */
        public static ArrayList<String> splitString(String text, int sliceSize) {
            ArrayList<String> textList = new ArrayList<String>();
            String aux;
            int left = -1, right = 0;
            int charsLeft = text.length();
            while (charsLeft != 0) {
                left = right;
                if (charsLeft >= sliceSize) {
                    right += sliceSize;
                    charsLeft -= sliceSize;
                }
                else {
                    right = text.length();
                    aux = text.substring(left, right);
                    charsLeft = 0;
                }
                aux = text.substring(left, right);
                textList.add(aux);
            }
            return textList;
        }

        /**
         * Divides a string into chunks.
         * 
         * @param text                  String text to be sliced
         * @return  ArrayList<String>   
         */
        public static ArrayList<String> splitString(String text) {
            return splitString(text, 80);
        }

        /**
         * Divides the string into chunks for displaying them
         * into the Eclipse's LogCat.
         * 
         * @param text      The text to be split and shown in LogCat
         * @param tag       The tag in which it will be shown.
         */
        public static void splitAndLog(String tag, String text) {
            ArrayList<String> messageList = Utils.splitString(text);
            for (String message : messageList) {
                Log.d(tag, message);
            }
        }
    }