什么导致我的代码错误?json_decode()期望参数1是字符串,给定的数组
$query = $this->db->query("SELECT * FROM tour_foreign ORDER BY id desc");
$data = array();
foreach ($query->result() as $row)
$data[] = array('guide' => $row->guide);
echo json_decode($data); //Line 167
错误:
erro: json_decode() expects parameter 1 to be string, array given: Line Number: 167
UPDATE:
如果使用json_encode
,不json_decode
我的输出是这样的:
[{"guide":["\u0633\u06cc\u062f \u0633\u0639\u06cc\u062f \u062f\u0627\u062f\u0627\u0634\u0632\u0627\u062f\u0647"]},{"guide":["\u0633\u06cc\u062f \u0633\u0639\u06cc\u062f \u062f\u0627\u062f\u0627\u0634\u0632\u0627\u062f\u0647"]},{"guide":null}]
他们是波斯语。
您正在传递一个数组,其中需要一个字符串。你之前正在创建数组 - 这是必要的吗?为什么不直接使用'$ row-> guide'? –
你想完成什么? –
你想在这里做什么? –