什麼導致我的代碼錯誤?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'? –
你想完成什麼? –
你想在這裏做什麼? –