Pretty-Printing JSON with PHP

后端 未结 24 1833
一向
一向 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 02:53

    best way to format JSON data is like this!

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

    Replace $response with your Data which is required to be converted to JSON

提交回复
热议问题