我需要一些說明如何糾正json的 的打印幅面我的代碼:如何將json格式從數組更改爲對象?
while($row = mysqli_fetch_array($result)){
//Step 4 Action current row
$img = $row['image'];
$link = $row['link'];
$posts[] = array('img'=> $img, 'url'=> $link);
//echo $row['image'] . "<br/> " ;
//echo $row['link'] . "<br/> " ;
}
echo json_encode($posts, JSON_PRETTY_PRINT);
輸出
[
{
"img": "catalog\/demo\/banners\/iPhone6.jpg",
"url": "index.php?route=product\/product&path=57&product_id=49"
},
{
"img": "catalog\/demo\/banners\/MacBookAir.jpg",
"url": ""
}
]
我想:
{
"img": "catalog\/demo\/banners\/iPhone6.jpg",
"url": "index.php?route=product\/product&path=57&product_id=49"
},
{
"img": "catalog\/demo\/banners\/MacBookAir.jpg",
"url": ""
}
使用'json_encode();'沒有JSON_PRETTY_PRINT – aldrin27
你想要的不是JSON。 – deceze