![](/img/trans.png)
[英]how to convert a json_encoded data to an associative array in php?
[英]How to convert json encoded data to array in codeigniter?
我有一个json编码的数据存储在我的数据库中。 我想将此json编码的数据转换为特定目的的数组。 我使用了json_decode函数,但由于出现错误,它似乎无法正常工作。 如何恢复以json格式保存在数据库中的数据的数组结构? 请帮忙。 这是我的代码。 非常感谢。
控制器功能
function show_at_report(){
$data = $this->data;
$report_id = $this->uri->segment(3);
$at_id = $this->uri->segment(4);
$query = $this->core_model->get_report_details($report_id,$at_id);
$a = $query['rows'];
var_dump($a);
foreach($a as $b){
var_dump($b);
}
}
输出:
修改后的控制器功能
function show_at_report(){
$data = $this->data;
$report_id = $this->uri->segment(3);
$at_id = $this->uri->segment(4);
$query = $this->core_model->get_report_details($report_id,$at_id);
$a = $query['rows'];
json_decode($a,TRUE);
var_dump($a);
foreach($a as $b){
json_decode($b,TRUE);
var_dump($b);
}
}
输出显示错误
这是什么问题? 如何将json数据恢复为数组?
$b
是一个数组,如错误所示, json_decode
需要一个字符串。 而且,如果我正确地看到了您真正想要解码的变量是$b[0]->data
因为$b
指向其中包含1个对象的数组,并且该对象有一个名为data
的公共变量,则该变量包含似乎是json。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.