json_decode()期望参数1为字符串,给定数组 [英] json_decode() expects parameter 1 to be string, array given

查看:178
本文介绍了json_decode()期望参数1为字符串,给定数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么原因导致我的代码出现此错误?

What causes this error in my code?

$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,则输出为:

If I use json_encode instead of json_decode, my output is this:

[{"guide":["\u0633\u06cc\u062f \u0633\u0639\u06cc\u062f \u062f\u0627\u062f\u0627\u0634\u0632\u0627\u062f\u0647"]},{"guide":["\u0633\u06c‌​c\u062f \u0633\u0639\u06cc\u062f \u062f\u0627\u062f\u0627\u0634\u0632\u0627\u062f\u0647"]},{"guide":null}]

它们是波斯语单词.

推荐答案

我认为您要 json_encode ,而不是 json_decode .

I think you want json_encode, not json_decode.

这篇关于json_decode()期望参数1为字符串,给定数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆