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.

PHP“Cannot use object of type stdClass as array”相关推荐

  1. lumen 配置数据库结果自动转数组_lumen 数据库操作 Cannot use object of type stdClass as array...

    你可能记得,操作数据库时 $dataList = 什么什么 ->get(); 能查询到数据 数据结果为数组加stdClass类型 你使用 $dataList = $dataList->to ...

  2. 数据集CollectionTP5报Cannot use object of type __PHP_Incomplete_Class as array错误

    本来是写登陆功能的时候将管理员数据保存到session中去,然后在BaseController中获取session并输出到模板,主要代码如下: login控制器 $result = AdminMode ...

  3. Pytorch 类型错误:Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor.

    Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor Pytorcht调试过程中,将数据传入模 ...

  4. python3运行报错:TypeError: Object of type ‘type‘ is not JSON serializable解决方法(详细)

    python3运行报错:TypeError: Object of type 'type' is not JSON serializable解决方法(详细) 参考文章: (1)python3运行报错:T ...

  5. Flask API TypeError: Object of type 'Response' is not JSON serializable

    Flask API TypeError: Object of type 'Response' is not JSON serializable 错误代码: session['image'] = str ...

  6. Object of type 'ndarray' is not JSON serializable

    Object of type 'ndarray' is not JSON serializable import numpy as np import jsonar=np.asarray([345,4 ...

  7. Object of type 'ListSerializer' is not JSON serializable “listserializer”类型的对象不可JSON序列化...

    Object of type 'ListSerializer' is not JSON serializable "listserializer"类型的对象不可JSON序列化 一般 ...

  8. 成功解决TypeError: object of type ‘int‘ has no len()

    成功解决TypeError: object of type 'int' has no len() 目录 解决问题 解决思路 解决方法 解决问题 TypeError: object of type 'i ...

  9. 成功解决TypeError: Object of type 'ndarray' is not JSON serializable

    解决问题 TypeError: Object of type 'ndarray' is not JSON serializable 解决方法 def default(self, obj):if isi ...

最新文章

  1. Android 使用GridView+仿微信图片上传功能(附源代码)
  2. php返回图片给安卓_android上传图片到PHP的过程详解
  3. 初创互联网公司简明创业指南 - YC新掌门Sam Altman
  4. 深度网络pre-train对于深度网络的意义
  5. matlab计算位温,大气物理学复习资料
  6. 安卓系统为何这么容易被黑客入侵
  7. 洛谷P1589 泥泞路
  8. Live2D在Unity中的使用
  9. 最新破解QQ空间收费物品的真实地址(完全可免费使用)
  10. 基于Javafx制作的随机抽签软件
  11. HTML/CSS class6 table布局
  12. HI3861学习笔记(12)——GPIO输入接口使用
  13. 微信域名防封系统-微信域名预拦截预防封
  14. 超链接 a标签 虚线框 虚线 去除虚线框
  15. python的self使用
  16. 如何在 Word 文档中添加水印?
  17. 无线路由器“无线漫游”
  18. 全网19套超热门表情包,小狗头、国王排名等我全部整理来了
  19. 电磁干扰的屏蔽方法~金属屏蔽效率
  20. pip更新及Requirement already up-to-date解决方法

热门文章

  1. 鸿蒙os操作系统合作伙伴,华为公布三大鸿蒙OS系统 已有大量合作伙伴进行开发...
  2. 2018年英语计算机职称考试,2018年职称计算机考试报考指南大全
  3. 利用c语言检测气体浓度,一氧化碳气体检测仪的算法设计
  4. java查询mysql装载bean_jsp与javabean链接mysql数据库并查询数据表的简单实例源码
  5. 4行指令解决pip下载Python第三方库太慢问题(pip更换国内下载源)
  6. STM32 GPIO的原理、特性、选型和配置
  7. NB-IoT模组低功耗设计:DRX、eDRX和PSM(NB-IoT专栏—拓展篇2)
  8. 【camera】基于深度学习的车牌检测与识别系统实现(课程设计)
  9. ROS发行版列表完整版
  10. 2014.4新版uboot启动流程分析