Pretty-Printing JSON with PHP

后端 未结 24 2217
一向
一向 2020-11-22 02:03

I\'m building a PHP script that feeds JSON data to another script. My script builds data into a large associative array, and then outputs the data using json_encode

24条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 03:01

    I have used this:

    echo "
    ".json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)."
    ";

    Or use php headers as below:

    header('Content-type: application/json; charset=UTF-8');
    echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    

提交回复
热议问题