这是print_r($query->getResult()):Array ( [0] => stdClass Object ( [id] => 9 [user_id] => [title] => [message] => [{"title":"Nice","option":"Text 1"},{"title":"nice 2","option":"text 2"},{"title":"nice 3","option":"text 3"}] [created_at] => 2020-06-21 16:59:49 ))我正在尝试使用以下命令来回应它:$query = $db->query("SELECT * from user_msg");foreach (json_decode($query->getResult()) as $key => $additional_field) { echo $additional_field->title;}但不幸的是我收到了这个错误:json_decode() 期望参数 1 为字符串,给定数组
1 回答
慕容3067478
TA贡献1773条经验 获得超3个赞
我不知道 CodeIgnitor,但根据结果数组和 JSON,您需要执行以下操作:
foreach ($query->getResult() as $row) {
foreach(json_decode($row->message) as $msg) {
echo $msg->title;
}
}
循环结果中的每一行,解码message并循环以获得titles。
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报
0/150
提交
取消