json_decode Cannot use object of type stdClass as array

admin
2011-11-05 / 0 评论 / 211 阅读 / 正在检测是否收录...

错误提示的意思是:Cannot use object of type stdClass as array 。 不能把对象作为数组使用。

问题出在json_decode 在第二个参数 bool $assoc 为默认true的时候,返还对象,而不是数组。

解决方法就简单了。
1:设置第二个参数为true

$r = json_decode($json,true);

2:返还结果用对象调用 $r ->var

0

评论 (0)

取消