我只是将我的语句结果作为JSON-Object回应。但是函数json_encode()将所有内容都放到一行中:
{"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}
现在设想一个包含数百个条目的JSON对象。
有没有办法添加一些<br>
标签或制表位以提高可读性?这应仅用于测试目的,而不是用于进一步解析。
答案 0 :(得分:4)
签出JSON_PRETTY_PRINT
标志。
echo json_encode([[[[[[['a'=>'b']]]]]]],JSON_PRETTY_PRINT);
输出:
[
[
[
[
[
[
{
"a": "b"
}
]
]
]
]
]
]