PHP json_decode返回数组和数字键


PHP json_decode return array and number key

我有以下JSON数组:

[
  {"r1t7pjT4wn":{"Title":"test","Meta":"test","SM_D":"test","BIG_D":"test"}},
  {"3rMlBu6LpZ":{"Title":"test1","Meta":"test1","SM_D":"test1","BIG_D":"test1"}}
]

当我做json_decode时,我希望看到:

Array ( 
  "r1t7pjT4wn" => Array ( [Title] => test [Meta] => test [SM_D] => test [BIG_D] => test ),
  "3rMlBu6LpZ" => Array ( [Title] => test1 [Meta] => test1 [SM_D] => test1 [BIG_D] => test1 )
)

然而,PHP产生:

Array ( 
  [0] => Array ( [r1t7pjT4wn] => Array ( [Title] => test [Meta] => test [SM_D] => test [BIG_D] => test ) ) 
  [1] => Array ( [3rMlBu6LpZ] => Array ( [Title] => test1 [Meta] => test1 [SM_D] => test1 [BIG_D] => test1 ) ) 
)

如果不能更改源json,请添加一个调用的函数

call_user_func_array('array_merge', json_decode($json, true));

这是因为数据是一个数组!如果它是关联数组(,如果它以{开始,以}结束),那么json_decode将具有您期望的输出。


将JSON更改为:

{
   "r1t7pjT4wn":{"Title":"test","Meta":"test","SM_D":"test","BIG_D":"test"},
   "3rMlBu6LpZ":{"Title":"test1","Meta":"test1","SM_D":"test1","BIG_D":"test1"}
}