0

如何快速轻松地保存嵌套在 php.ini 中的 JSON。我对嵌套的意思是:

嵌套的json:

{
    "key1":"value",
    "key2":"value",
    "key3":"value",
    "key4":{
        "key1":"value",
        "key2":"value",
        "key3":"value"
    },
    "key5":{
        "key1":"value",
        "key2":"value",
        "key3":"value"
    }
}

json 放在一行中(当我只使用 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 必须易于人类阅读。当一切都在一条线上没有帮助时。

4

1 回答 1

1

为(PHP >= 5.4)使用正确的$options参数json_encode

echo json_encode($object, JSON_PRETTY_PRINT);
于 2013-09-26T06:47:56.643 回答