[英]json viewer library for php
I would like to show my json string like this : 我想像这样显示我的json字符串:
but if I echo my json output it shows like this: 但如果我回显我的json输出,它显示如下:
{"Status":2,"TokenReg":"eeea7930efeb7715697a2035fcee3fdf","AllScores":"305","User_ID":"16433"}
is there any plugin/library to show json string as well as above image (formatted json) ? 是否有任何插件/库来显示json字符串以及上面的图像(格式化json)?
When you use json_encode
in PHP you can specify the JSON_PRETTY_PRINT
option. 在PHP中使用
json_encode
,可以指定JSON_PRETTY_PRINT
选项。
echo json_encode(["foo" => ["bar" => ["baz" => "quix"]]], JSON_PRETTY_PRINT);
This gives you output like this. 这给你这样的输出。
{ "foo": { "bar": { "baz": "quix" } } }
If what you already have is a string you can just decode first and the encode. 如果您已经拥有的是一个字符串,您可以先解码并编码。
$str = '{"Status":2,"TokenReg":"eeea7930efeb7715697a2035fcee3fdf","AllScores":"305","User_ID":"16433"}';
echo json_encode(json_decode($str), JSON_PRETTY_PRINT);
This should give you the desired output. 这应该给你想要的输出。
{ "Status": 2, "TokenReg": "eeea7930efeb7715697a2035fcee3fdf", "AllScores": "305", "User_ID": "16433" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.