這是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 ))我正在嘗試使用以下命令來(lái)回應(yīng)它:$query = $db->query("SELECT * from user_msg");foreach (json_decode($query->getResult()) as $key => $additional_field) { echo $additional_field->title;}但不幸的是我收到了這個(gè)錯(cuò)誤:json_decode() 期望參數(shù) 1 為字符串,給定數(shù)組
1 回答

慕容3067478
TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊
我不知道 CodeIgnitor,但根據(jù)結(jié)果數(shù)組和 JSON,您需要執(zhí)行以下操作:
foreach ($query->getResult() as $row) {
foreach(json_decode($row->message) as $msg) {
echo $msg->title;
}
}
循環(huán)結(jié)果中的每一行,解碼message并循環(huán)以獲得titles。
- 1 回答
- 0 關(guān)注
- 133 瀏覽
添加回答
舉報(bào)
0/150
提交
取消