【发布时间】:2013-12-16 13:54:56
【问题描述】:
我的数据库中存储了一个 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 数据返回到数组中?
【问题讨论】:
-
我认为你需要遍历
$a并将json_decode应用于循环中的每一行。 -
var_dump($a)或print_r($a)看看里面有什么。 -
试试 json_decode($b->data,TRUE)
标签: php arrays json codeigniter