关于php:我可以使用< br>改进“json_encode”结果的可读性

Can i improve “json_encode” results readability with <br> tags?

本问题已经有最佳答案,请猛点这里访问。

我只是将我的语句结果作为JSON对象进行重复。但是函数json_encode()将所有内容都放到一行中,如下所示:

1
{"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3"0":{"username":"Olli"},"1":{"username":"Heiner"},"2":{"username":"Rolf"},"success":true,"rowcount":3}

现在想象一个JSONObject有更多的条目。

有没有办法添加一些标签或制表位来提高可读性?这只能用于测试目的,不能用于进一步分析。


签出JSON_PRETTY_PRINT标志。

1
echo json_encode([[[[[[['a'=>'b']]]]]]],JSON_PRETTY_PRINT);

输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[
    [
        [
            [
                [
                    [
                        {
                           "a":"b"
                        }
                    ]
                ]
            ]
        ]
    ]
]

参考:http://php.net/json_encode