php在调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误
一、错误位置
报错如图所示:
报错代码
二、解决办法
1、使用json_decode($res,true ) 。就是使jsond_ecode的第二个变量设置为true 。
$data = json_decode($data,true);
2、json_decode($res) 返回的是一个对象, 不可以使用 $res[‘key’] 进行访问, 换成 $res->key 就可以了。
三、原因
$res = json_decode($res);
$res['key']; //把 json_decode() 后的对象当作数组使用。
{{item.user_info.nickname}} {{item.user_info.is_threads ? '(管理员)' : item.user_id == thread_uid ? '(作者)' : ''}}
{{item.user_name}} {{item.user_info.is_threads ? '(管理员)' : item.user_id == thread_uid ? '(作者)' : ''}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}