【问题标题】:PHP: access object with key intPHP:使用键 int 访问对象
【发布时间】:2015-01-05 19:53:36
【问题描述】:

我收到这种格式的 json:

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

注意:106371527,10003989 个用户 ID

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

如何解决这个问题?

谢谢,

【问题讨论】:

标签: php json object


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我刚刚找到答案,使用:

    json_decode($json, true); 
    

    返回数组而不是对象,

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

    谢谢,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-03
      • 2013-06-14
      • 2019-10-20
      • 2020-07-25
      • 1970-01-01
      • 2018-07-15
      • 2014-02-09
      • 2011-02-12
      相关资源
      最近更新 更多