不再数组json和如何警告json数据在jquery


No longer array json and how to alert json data in jquery

不知道为什么不再是数组,也不知道为什么{},{}之间没有逗号

foreach ($query->result_array() as $row) {
    header("Content-type: application/json");
    echo (json_encode($row,JSON_PRETTY_PRINT));
}

和如何警报json数据在jquery?在此之前,我在js中使用for循环来循环它,但由于某种原因,我现在必须在服务器端循环。

编辑
//because i want to replace $row['url'] to get_thumb();    
foreach($query->result_array() as $row){
        $row['url'] = $this->vz_image->get_thumb($row['url'],'n');
        header("Content-type: application/json");
    echo (json_encode($row,JSON_PRETTY_PRINT));
    }

然后我得到了这个结果,但我不知道如何在jquery中提醒这个json数据。任何帮助吗?

{
"id": "44",
"url": "assets'/img'/uploaded_photos'/thumbs'/1358786330_n.jpg",
"created_time": "1358786330",
"photo_id": "170",
"tag_id": "44",
"name": "Lan Yao Yeng",
"num_photo": "3"
}{
"id": "44",
"url": "assets'/img'/uploaded_photos'/thumbs'/1358711532_n.jpg",
"created_time": "1358711532",
"photo_id": "169",
"tag_id": "44",
"name": "Lan Yao Yeng",
"num_photo": "3"
}

它不是一个数组,因为你没有给它一个数组。

你正在一个接一个地重复一些对象;

如果要将整个数组传递给客户端,只需对数组本身进行编码,而不是对每个元素进行编码。

function map($row){
    if (isset($row['url']))
        $row['url'] = $this->vz_image->get_thumb($row['url'],'n');
    return $row;
}
header("Content-type: application/json");
echo json_encode(array_map("map", $query->result_array()),JSON_PRETTY_PRINT);

如果你在一个类中使用这个,你可能不得不把array_map("map", $query->result_array())改为array_map(array($this, "map"), $query->result_array())