繁体   English   中英

Json漂亮打印失败

[英]Json pretty print fails

我的Android API 15级有此代码

        JSONArray l = new JSONArray();
        JSONObject a = new JSONObject();
        a.put("a", "a");
        a.put("b", "a");
        a.put("c", "d");
        l.put(a);
        a = new JSONObject();
        a.put("d", "a");
        a.put("g", "3");
        l.put(a);

        Log.d(TAG, l.toString(3));
        Log.d(TAG, l.toString());

输出是这个

DEBUG   test    [
DEBUG   test       {
DEBUG   test          "b": "a",
DEBUG   test          "c": "d",
DEBUG   test          "a": "a"
DEBUG   test       },
DEBUG   test          "g": "3",
DEBUG   test          "d": "a"
DEBUG   test       }
DEBUG   test    ]
DEBUG   test    [{"b":"a","c":"d","a":"a"},{"g":"3","d":"a"}]

漂亮的打印输出缺少第二个JSONObject的开头{。 这是一个已知的错误 ?

(使用Gson时也是如此。)

编辑:

它对我来说运作良好,我正在使用Intellij:

10-15 14:18:43.433: DEBUG/it.enrichman.myapp(4470): [
        {
        "b": "a",
        "c": "d",
        "a": "a"
        },
        {
        "g": "3",
        "d": "a"
        }
        ]

所以我想Eclipse(照常)搞乱了日志。 :)


为什么这应该是一个错误? 这是预期的行为。

toString(int indentSpaces)会漂亮地打印出来,普通的toString()只会输出json。 它也写在文档中:

公共字符串toString()

将此数组编码为紧凑的JSON字符串

public String toString(int indentSpaces)

将此数组编码为可读的JSON字符串以进行调试

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM