PHP“Cannot use object of type stdClass as array”
php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误
错误:
Cannot use object of type stdClass as array
产生原因:
$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”的更多相关文章
- 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 ...
- PHP json_decode object时报错Cannot use object of type stdClass as array
PHP json_decode object时报错Cannot use object of type stdClass as array php再调用json_decode从字符串对象生成json对象 ...
- iwebshop (: Cannot use object of type stdClass as array in)
今天在PHP输出一个二维数组的时候,出现了“Fatal error: Cannot use object of type stdClass as array in……”. 这个二维数组是这样的: Ar ...
- **PHP错误Cannot use object of type stdClass as array in错误的
错误:将PHP对象类型当做了PHP数组 解决方法:用对象操作符-> 今天在PHP输出一个二维数组的时候,出现了“Fatal error: Cannot use object of type s ...
- Fatal error: Cannot use object of type PHPExcel_RichText as array
Fatal error: Cannot use object of type PHPExcel_RichText as array 上传导入Excel的时候会出现此问题,问题的原因是Excel表格中有 ...
- MyBatis Generator报错:Cannot instantiate object of type
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate ( ...
- spring boot 之 错误:SpelEvaluationException: EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap'
这个错误我也见过很多次了,今天终于理解了其出现的原因. 错误是这样的: 2017-11-23 18:05:39.504 ERROR 4092 --- [nio-8080-exec-3] o.a.c.c ...
- Unable to cast object of type 'System.Int32' to type 'System.Array'.
x 入职了新公司.最近比较忙...一看博客...更新频率明显少了...罪过罪过... 新公司用ASP.NET MVC 遇上一个错误: Unable to cast object of type 'Sy ...
- celery 4.1下报kombu.exceptions.EncodeError: Object of type 'bytes' is not JSON serializable 处理方式
#python代码如下 from celery import Celeryimport subprocess app = Celery('tasks', broker='redis://localho ...
随机推荐
- python基础===python os.path模块
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- Linux kernel suspend resume学习:2.6.35与3.0.35比较【转】
转自:http://blog.csdn.net/njuitjf/article/details/18317149 Linux kernel suspend resume学习:2.6.35与3.0.35 ...
- sicily 1052. Candy Sharing Game
Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A number of students sit in a circle ...
- iOS一个项目开始创建, 部署到git服务器
在做iOS开发时, 最开始可能你的经理部署项目, 所以你不会插手, 只是直接从git上clone下来然后就开始撸码, 如果有一天你做经理了, 你怎么去部署一个项目呢, 下面我来过一遍流程 1. 首先需 ...
- Smarty模板快速入门
文件下载 1.下载地址:http://www.smarty.net/ 2.我下载的版本是3.1.27 ,将下载的文件smarty-3.1.27.zip解压出来,然后将libs文件夹的所有文件复制到你的 ...
- MD5加密学习
MD5(Message Digest --消息摘要算法)算法是一种散列(hash)算法(摘要算法,指纹算法),不是一种加密算法(易错),任何长度的任意内容都可以用MD5计算出散列值.主要作用是[验明“ ...
- mui 选项卡与header文字同步
mui底部tab固定 头部nav可变 <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- Every Tom,Dick and Harry. 不管张三李四。
1 every adj 每个,最大的,所有的,一切的 Every other girl except me is wearing jeans. 除了我之外的每个女孩都穿着牛仔裤. I have ...
- mysql 安装和配置
mysql 安装: 在命令行输入 sudo apt-get install mysql-server 安装过程中会跳出来一个窗口,输入数据库root用户的密码(必须输入密码) 安装完成后 通过 my ...
- 封装ajax方法
function ajaxRequest(type, url, data, callback, loading, cache) { var ajaxConfig = { url: '', data: ...