Format echo json
This question already has an answer here:
The first piece of advice I'd give is: Don't. JSON is a data format. Deal with it using tools rather then trying to have your server format it.
If you are going to ignore that, then see the manual for the json_encode
function where it gives a list of options which includes JSON_PRETTY_PRINT
which is described as Use whitespace in returned data to format it. Available since PHP 5.4.0.
Thus the steps are:
json_encode($data, JSON_PRETTY_PRINT);
You can use json_encode($data, JSON_PRETTY_PRINT)
in php 5.4+
In php 5.3 & under that, you could try formatting it with regular expressions, but it's not too safe (or you could use library for encoding json).
链接地址: http://www.djcxy.com/p/47270.html下一篇: 格式化echo json