PHP json_decode object时报错Cannot use object of type stdClass as array

php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误
错误:
Cannot use object of type stdClass as array

产生原因:
$res = json_decode($res);
$res['key']; //把 json_decode() 后的对象当作数组使用。

解决方法(2种):
1、使用 json_decode($data, 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.

PHP json_decode object时报错Cannot use object of type stdClass as array的更多相关文章

  1. PHP“Cannot use object of type stdClass as array” (php在调用json_decode从字符串对象生成json对象时的报错)

    php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误 错误:Cannot use object of type stdClass as arra ...

  2. PHP“Cannot use object of type stdClass as array”

    php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误 错误:Cannot use object of type stdClass as arra ...

  3. iwebshop (: Cannot use object of type stdClass as array in)

    今天在PHP输出一个二维数组的时候,出现了“Fatal error: Cannot use object of type stdClass as array in……”. 这个二维数组是这样的: Ar ...

  4. **PHP错误Cannot use object of type stdClass as array in错误的

    错误:将PHP对象类型当做了PHP数组  解决方法:用对象操作符-> 今天在PHP输出一个二维数组的时候,出现了“Fatal error: Cannot use object of type s ...

  5. PyQt(Python+Qt)学习随笔:自定义信号在emit发射信号时报错:AttributeError: object has no attribute

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 如果使用自定义信号,一定要记得信号是类变量,必须在类中定义,不能在实例 ...

  6. facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' object has no attribute 'iteritems'

    报错原因:在进行facenet进行train_softmax.py训练时,在一轮训练结束进行验证时,报错AttributeError: 'dict' object has no attribute ' ...

  7. 解决Linq Join Group by 时报错:Nullable object must have a value.

    Linq Join Group by 时报Nullable object must have a value. 例如: from s in subject on ch.SubId equals s.S ...

  8. peewee insert 数据时报错:'buffer' object has no attribute 'translate'

    错误信息: "'buffer' object has no attribute 'translate'" 场景:使用peewee insert 数据时,BlobField 字段存储 ...

  9. zc.buildout构建项目时报错‘AttributeError: '_NamespacePath' object has no attribute 'sort'’

    在使用zc.buildout构建项目时如果碰到‘AttributeError: '_NamespacePath' object has no attribute 'sort'’报错: An inter ...

随机推荐

  1. .net 4.0 ValidateRequest="false"

    在安装了Visual Studio 2010 Beta2之后,当页面输入框默认情况下输入"<"或者">"的时候.按照访问策略,这将导致一些安全问题, ...

  2. JavaScript:window窗口对象

    在JavaScript中,window表示的就是一个窗口对象.所以在整个处理过程之中,所有的操作都是以弹框为主 的.范例1:使用警告框 <script type="text/javas ...

  3. ELK-Python(二)

    不具有通用性,留作纪念. [root@GXB-CTRLCENTER python]# cat insert_pv.py #!/usr/bin/env python # -*- coding:utf-8 ...

  4. node的passport.js验证

    项目使用的是passport.js(http://passportjs.org/docs),所以对passport这个中间件研究了一番,在本项目中passport同express-session配合使 ...

  5. 重新拷贝 新项目 发现不显示 原来是 paramiko 没有装

    proxy pass 端口换成 另一个 跟原来的不冲突 [root@ayibang-server soft_ware]# cp s10day11/demo.* s10ops/[root@ayibang ...

  6. myeclipse中的web项目导入到eclipse中注意事项,项目部署到tomcat后无法访问jsp文件

    打开eclipse,点击空白处,右键可以看到import>general>existing projects into workspace>next>选择你的myeclipse ...

  7. 防止IE不支持console.log报错

    function log(msg){ if (window["console"]){//判断是否是IE console.log(msg); } }

  8. First learning operation system

    1,操作系统负责管理硬件资源,为应用程序的开发执行提供基础 2,用户空间包括应用程序,只能通过调用系统调用访问硬件,无法访问更小粒度功能 3,设备驱动程序函数和内核子系统的函数对用户不可见 4,操作系 ...

  9. 减去border边框

    width: 100%; border: 1px solid transparent; box-sizing: border-box;

  10. linux:问题

    1>.Xshell远程连接linux闲置时间过长会自动中断连接: 2>.在linux环境下乱码: 3>.在linux下面执行mv /bin/ls /root/bin之后执行ls就不能 ...