Represent JSON data from one line string to structured source
This question already has an answer here:
Use JSON_PRETTY_PRINT
flag (PHP 5.4+):
$json_str = json_encode($data, JSON_PRETTY_PRINT);
Since you're having a JSON-string, you can first decode it into an object, and then re-encode it.
Example:
$str = '{"name":"John","age":"12","Location":"U.S.A"}';
echo json_encode(json_decode($str), JSON_PRETTY_PRINT);
Output:
{
"name": "John",
"age": "12",
"Location": "U.S.A"
}
Demo
链接地址: http://www.djcxy.com/p/47272.html上一篇: 格式化json内容输出