I'm using json_ecnode, and later json_decode in PHP. for some reason, even though i'm encoding an array with json_encode, it always comes out as an object after the json_decode decoding.
I have no control over the json_decode part as some other system is decoding it and using it. I'm the one dealing with the encoding part. what can I do to make it decode as an array?
here is in example code:
$types = array(
'aa1' => array('type' => 'document/unknown', 'icon' => 'unknown'),
'aa2' => array('type' => 'video/quicktime', 'icon' => 'quicktime', 'groups' => array('video'), 'string' => 'video')
);
var_dump($types);
$typesencoded = json_encode($types);
var_dump($typesencoded);
$typesdecoded = json_decode($typesencoded);
var_dump($typesdecoded);
and this is the output:
/tests/test.php:28:array (size=2)
'aa1' =>
array (size=2)
'type' => string 'document/unknown' (length=16)
'icon' => string 'unknown' (length=7)
'aa2' =>
array (size=4)
'type' => string 'video/quicktime' (length=15)
'icon' => string 'quicktime' (length=9)
'groups' =>
array (size=1)
0 => string 'video' (length=5)
'string' => string 'video' (length=5)
/tests/test.php:35:string '{"aa1":{"type":"document\/unknown","icon":"unknown"},"aa2":{"type":"video\/quicktime","icon":"quicktime","groups":["video"],"string":"video"}}' (length=142)
/tests/test.php:40:
object(stdClass)[78]
public 'aa1' =>
object(stdClass)[77]
public 'type' => string 'document/unknown' (length=16)
public 'icon' => string 'unknown' (length=7)
public 'aa2' =>
object(stdClass)[79]
public 'type' => string 'video/quicktime' (length=15)
public 'icon' => string 'quicktime' (length=9)
public 'groups' =>
array (size=1)
0 => string 'video' (length=5)
public 'string' => string 'video' (length=5)