您当前的位置: 首页 >  ar

PHP“Cannot use object of type stdClass as array”

发布时间:2011-07-12 12:43:31 ,浏览量:0

 php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误 错误: Cannot use object of type stdClass as array 产生原因:
+展开
-PHP
     $res = json_decode( $res);      $res[ 'key'];  //把 json_decode() 后的对象当作数组使用。
解决方法(2种): 1、使用 json_decode($d, true)。就是使json_decode 的第二个变量设置为 true。 2、json_decode($res) 返回的是一个对象, 不可以使用 $res['key'] 进行访问, 换成 $res->key 就可以了。 参考手册:json_decode Return Values:Returns an object or if the optional assoc parameter is TRUE, an associative array is instead returned.
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108268博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0458s