是什么原因导致我的代码出现此错误?
$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
更新:
如果我使用 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}]
它们是波斯语单词。
最佳答案
我想你想要json_encode
, 不是 json_decode
.
关于php - json_decode() 期望参数 1 为字符串,数组给定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7436925/