如何快速轻松地保存嵌套在php中的JSON。我对嵌套的意思是:
嵌套json:
{
"key1":"value",
"key2":"value",
"key3":"value",
"key4":{
"key1":"value",
"key2":"value",
"key3":"value"
},
"key5":{
"key1":"value",
"key2":"value",
"key3":"value"
}
}
json plain in one line (当我只使用echo json_encode($ array)):
{"key1":"value","key2":"value","key3":"value","key4":{"key1":"value","key2":"value","key3":"value"},"key5":{"key1":"value","key2":"value","key3":"value"}}
我想要的原因是json必须易于人类阅读。当所有事情都在一条线上被打乱时,这无济于事。
答案 0 :(得分:1)
为json_encode
使用正确的$options
参数(PHP> = 5.4)
echo json_encode($object, JSON_PRETTY_PRINT);