PHP:使用键int访问对象


PHP: access object with key int

我收到的json格式如下:

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

注意:10637152710003989用户识别

当我使用json_decode()时,仍然无法访问数据,因为对象密钥是int,

如何解决这个问题?

谢谢,

您还应该能够通过将属性包装在{}:中来访问该属性

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

我刚刚找到了答案,使用:

json_decode($json, true); 

返回数组而不是对象,

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

谢谢,