我JSON元素json_decode轉換空數組字符串
{"element":{},
"gallery":{
"images":[
{"id":"1","description":{},"image_path":"1.jpg"},
{"id":"2","description":"Test","image_path":"2.jpg"}
]},
"additional_value":"Test"}
PHP函數json_decode($ JSON,TRUE)返回
Array
(
[element] => Array()
[gallery] => Array(
[images] => Array(
[0] => Array(
[id] => 1
[description] => Array()
[image_path] => 1.jpg)
[1] => Array(
[id] => 2
[description] => Test
[image_path] => 2.jpg)
)
)
[additional_value] => Test
)
我怎麼能代替/轉換空數組字符串?例如:
[0] => Array([id] => 1
[description] => ""
[image_path] => 1.jpg)
謝謝!
如果您無法避免將'description'設置爲JSON對象,則必須使用PHP手動進行轉換。 – RhinoDevel
要添加到@RhinoDevel,您可以使用'array_walk_recursive()'。 – frz3993
@ frz3993原來不行。 – GolezTrol