php浏览器JSON输出,安装浏览器插件JSONViewer
//原始字符串,JSON格式
$origin_str = '{"code":200,"data":[{"color":"red","name":"红色","rgb":"ff0000"},{"color":"green","name":"绿色","rgb":"00ff00"},{"color":"blue","name":"蓝色","rgb":"0000ff"}]}';
//对原始字符串进行解码,转换为PHP对象或数组
$json_obj = json_decode($origin_str);
//对PHP对象或数组重新进行JSON编码,生成新的字符串
//默认情况下,字符串中的中文会进行Unicode编码
//多个配置参数之间,用竖线分隔
$json_str = json_encode($json_obj, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
//页面输出
echo '<pre>';
echo $json_str;
echo '</pre>';