PHP“Cannot use object of type stdClass as array” (php在调用json_decode从字符串对象生成json对象时的报错)
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.
返回值默认是JSON对象,当第二个可选参数是TRUE的时候,则返回的是数组
PHP“Cannot use object of type stdClass as array” (php在调用json_decode从字符串对象生成json对象时的报错)的更多相关文章
- 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 ...
- PHP“Cannot use object of type stdClass as array”
php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误 错误:Cannot use object of type stdClass as arra ...
- Fatal error: Cannot use object of type PHPExcel_RichText as array
Fatal error: Cannot use object of type PHPExcel_RichText as array 上传导入Excel的时候会出现此问题,问题的原因是Excel表格中有 ...
- 运行python脚本时,报错InsecurePlatformWarning: A true SSLContext object is not available,解决方法
今天,要在新环境里运行一个python脚本,遇到下面的报错: /usr/lib/python2.7/site-packages/urllib3/util/ssl_.py:160: InsecurePl ...
- 在angular项目中使用bootstrap的tooltip插件时,报错Property 'tooltip' does no t exist on type 'JQuery<HTMLElement>的解决方法和过程
在angular4的项目中需要使用bootstrap的tooltip插件. 1. 使用命令安装jQuery和bootstrap npm install bootstrap jquery --save ...
- for遍历用例数据时,报错:TypeError: list indices must be integers, not dict,'int' object is not iterable解决方法
一:报错:TypeError: list indices must be integers, not dict for i in range(0,len(test_data)): suite.addT ...
- 使用xadmin更新数据时,报错expected string or bytes-like object
expected string or bytes-like object 期望的字符串或类似字节的对象,一般为数据类型不匹配造成 本人在实际项目里发现的问题是: 数据库里的字段类型与django里mo ...
随机推荐
- 使用SqlSessionTemplate实现数据库的操作
EmployeeMapper.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE map ...
- QueryHelp
//辅助查询 Author:高兵兵 public class QueryHelp { #region IList<T> ToList<T>(string cmdText,str ...
- NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager 解决方法
差一个jar包, 将hibernate-commons-annotations.jar加入到classpath中
- 最长公共子序列(LCS)
简单的DP. f[i][j]表示序列a中前i个中,序列b中前b个中,组成的最长公共子序列的长度. DP方程: if(a[i-1]==b[j-1]) f[i][j]=f[i-1][j-1]+1; el ...
- 移动前端调式页面--weinre
一:远程调式工具---weinre 阅读目录 一:远程调式工具---weinre 二: 安装weinre 三: 访问weinre及在页面上调用 四:多用户 回到顶部 一:远程调式工具---weinre ...
- zoj.3865.Superbot(bfs + 多维dp)
Superbot Time Limit: 2 Seconds Memory Limit: 65536 KB Superbot is an interesting game which you ...
- Spell checker(暴力)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20188 Accepted: 7404 De ...
- Python打包程序
到py2exe的官网下载程序,注意对应的python版本,比如所用的python版本为2.7,那么就下载适配2.7版本的py2exe软件 下载完成后安装(与普通软件安装方式相同) 2 将要转换的pyt ...
- iOS UILabel圆角
对于UIView 直接设置 uiview.layer.cornerRadius = 5 就可以有圆角了 但是对于UILabel则不然, 要多设置一个uilabel.clipsToBounds = YE ...
- asp.net 网站 或者web Api 发布
asp.net 发布iis时可能遇到的内部服务错误常见的有两种: 1.如下图,500.19 Internal Server Error(内部服务错误) 这种错误可能是由于本机的注册表中的asp.net ...