我可以使用 <br> 标签提高“json_encode”结果的可读性吗? [复制]
Posted
技术标签:
【中文标题】我可以使用 <br> 标签提高“json_encode”结果的可读性吗? [复制]【英文标题】:Can i improve "json_encode" results readability with <br> tags? [duplicate] 【发布时间】:2018-03-15 17:44:31 【问题描述】:我只是将我的语句结果作为 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>
标签或制表位来提高可读性?这应该仅用于测试目的,而不是用于进一步解析。
【问题讨论】:
为什么不改为json_decode呢? @tilz0R: ...然后炸毁试图使用 JSON 的另一端。 【参考方案1】:查看JSON_PRETTY_PRINT
标志。
echo json_encode([[[[[[['a'=>'b']]]]]]],JSON_PRETTY_PRINT);
输出:
[
[
[
[
[
[
"a": "b"
]
]
]
]
]
]
参考:http://php.net/json_encode
【讨论】:
请不要回答明显重复。找到欺骗目标并投票关闭。 @T.J.Crowder 恕我直言,先生,我怀疑你从来没有自己做这件事并没有赢得 570k 代表(例如:***.com/questions/39611979/…)。考虑到现在很多答案,比如这个答案,都必须非常很快地写出来。很容易忽略重复检查。以上是关于我可以使用 <br> 标签提高“json_encode”结果的可读性吗? [复制]的主要内容,如果未能解决你的问题,请参考以下文章
使用 Google App Engine 和 Jinja2 允许 <br> 标签
使用 BeautifulSoup 解析未关闭的 `<br>` 标签