你的位置:飞飞的个人网站 > 资讯 > php json_encode “Cannot use object of type stdClass as array” 的解决方法
php json_encode “Cannot use object of type stdClass as array” 的解决方法资讯 feifei 3年前 (2012-11-01) 517浏览
错误:Cannot use object of type stdClass as array
产生原因:$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 就可以了。
Return Values:Returns anobjector if the optionalassocparameter isTRUE, an associativearrayis instead returned.
转载请注明:飞飞的个人网站 » php json_encode “Cannot use object of type stdClass as array” 的解决方法
分享到
上一篇 网站响应头http错误代码表 天敏的电视盒黑屏情况下调分辨率的方法 下一篇与本文相关的文章