2

I receive jsons in this format:

{"106371527":[33,22,11,2],"10003989":[3,2,11,3]}

note: 106371527,10003989 users ids

when I use json_decode(), still can't access data because the object keys is int,

how to fix this?

thanks,

mwafi
  • 3,946
  • 8
  • 56
  • 83
  • 1
    possible duplicate of [How to access object properties with names like integers?](http://stackoverflow.com/questions/10333016/how-to-access-object-properties-with-names-like-integers) – sectus Nov 09 '14 at 12:27

2 Answers2

1

I just found the answer, use:

json_decode($json, true); 

to return array rather than object,

http://php.net/manual/en/function.json-decode.php

thanks,

mwafi
  • 3,946
  • 8
  • 56
  • 83
1

You should also be able to access the property by wrapping it in {}:

$json = '{"106371527":[33,22,11,2],"10003989":[3,2,11,3]}';
$object = json_decode($json);
print_r($object->{106371527});
Cyclonecode
  • 29,115
  • 11
  • 72
  • 93