【发布时间】:2017-08-30 06:45:55
【问题描述】:
我出现这个错误:
htmlspecialchars() expects parameter 1 to be string, object given
我在控制器中使用:
$data = '{"pr":{"code":"1"},"ac":[[{"icon":"web","action":"link","url":"asd"}]]}'
$newData = json_decode($data);
我将它作为数组发送到视图:'data' => $newData 当我尝试在视图中使用 $data 时,它给了我这个错误
已经尝试使用 $data->ac OR $data['ac'] 但还是一样... 请帮忙?
【问题讨论】:
-
可以添加视图的代码吗?
-
{{ $data }} => 就是这样。
-
json_decode 默认返回一个对象。对数组使用
$newData = json_decode($data,TRUE); -
htmlspecialchars() 期望参数 1 是字符串,给定数组