PHP json_解码返回数组和数字键

PHP json_解码返回数组和数字键,php,arrays,json,Php,Arrays,Json,我有以下JSON数组: [ {"r1t7pjT4wn":{"Title":"test","Meta":"test","SM_D":"test","BIG_D":"test"}}, {"3rMlBu6LpZ":{"Title":"test1","Meta":"test1","SM_D":"test1","BIG_D":"test1"}} ] 当我进行json解码时,我希望看到: Array ( "r1t7pjT4wn" => Array ( [Title] => tes

我有以下JSON数组:

[
  {"r1t7pjT4wn":{"Title":"test","Meta":"test","SM_D":"test","BIG_D":"test"}},
  {"3rMlBu6LpZ":{"Title":"test1","Meta":"test1","SM_D":"test1","BIG_D":"test1"}}
]
当我进行json解码时,我希望看到:

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_decode
将具有您期望的输出


将您的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
将具有您期望的输出


将您的JSON更改为:

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

如果无法更改源json,请添加一个函数调用

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

如果无法更改源json,请添加一个函数调用

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