php - json_decode() 期望参数 1 为字符串,数组给定

标签 php json

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

$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\u06c‌​c\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/

相关文章:

javascript - 解析页面当前项后执行 "Load more products"

json - Angular 5 Typescript - 保存本地 JSON 文件

python - 从字符串中提取哈希数字

javascript - 向 Google Maps API 发出 GET 请求返回错误请求 400 错误 - javascript

php - Android + Json通过php将部分spinner值插入mysql

php - 无法在 laravel 中创建表

php - 调用未定义的方法 mysqli_stmt::get_result() 和安装的 mysqlnd

php - 识别 HTML 元素的最佳方法是什么

php - Silex Framework 中具有动态替换的 YAML 配置文件

php - 如何在 IOS 上使用 Swift 解析从 PHP 服务脚本发送的 JSON?