PHP json_decode返回数组和数字键

I have the following JSON array:

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

When I do json_decode, I expect to see:

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 )
)

However, PHP yields:

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 ) ) 
)

This is because your data is an array! If it were an associative array (i.e. if it began with { and ended with }) then json_decode would have the output you expect.


Change your JSON to:

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

if you can't change source json, add one function call

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