php再调用json_decode从字符串对象生成json对象时出现Cannot use object of type stdClass as array解决方法

admin5年前php1032

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

Cannot use object of type stdClass as array

产生原因:

一.有其他的不正常输出,好好检查一下删除其余的输出就可以了


二.解决方法(2种):

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


1、使用 json_decode($d, true)。就是使json_decode 的第二个变量设置为 true。

2、json_decode($res) 返回的是一个对象, 不可以使用 $res['key'] 进行访问, 换成 $res->key 就可以了。


相关文章

php post undefined index,PHP 中提示undefined index的解决方案

声明为空isset($_POST['user_email']),或者,empty($_POST['user_email'])在php.ini中设置error_repor...

php下载地址

https://windows.php.net/downloads/releases/archives/...

面向过程的php sqlhelp

<?php $servername = "localhost"; $username = "root"; $...

批量插入

一条insert语句批量插入多条记录原创|浏览:138554|更新:2017-12-19 08:21一条insert语句批量插入多条记录常见的insert语句,向数据库中,一条语句只能插入一条数据:i...

php.ini 7.3设置

date.timezone = PRCdisplay_errors = On网络保存图片,以及微信获取手机号码: windows下的PHP,只需要到php.ini中把前面的&nb...

php提示Notice: Undefined index解决方法与php未定义的变量提示错误的解决方法

在php.ini配置文件里设置把error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT修改成error_reporting = E_AL...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。