2016-04-03 22 views
0

Aşağıdaki JSON dizi var: Ben json_decode yaptığınızdaPHP json_decode dönüş dizi ve anahtar numarası

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

, ben görmeyi beklediğiniz:

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

Ancak PHP verimleri:

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

cevap

2

Bunun nedeni, verilerinizin'dur. bir dizi! ilişkisel dizilimi (, yani { ile başladıysa ve } ile biten) ise, beklediğiniz çıktının json_decode olması gerekir.


için JSON değiştirin

: Kaynak json değiştiremiyorsanız,

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

bir işlev çağrısı eklemek

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