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

Jen*_*ony 14 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
Run Code Online (Sandbox Code Playgroud)

错误:

erro: json_decode() expects parameter 1 to be string, array given: Line Number: 167
Run Code Online (Sandbox Code Playgroud)

更新:

如果使用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}]
Run Code Online (Sandbox Code Playgroud)

他们是波斯语.

Roc*_*mat 45

我想你想要的json_encode不是json_decode.


Kar*_*eem 14

您的解码未设置为true.如果您无权将源设置为true.下面的代码将为您解决.

$WorkingArray = json_decode(json_encode($data),true);
Run Code Online (Sandbox Code Playgroud)