php - how to change json format from array to object? -


i need description how correct print format of json code:

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); 

the output

[      {         "img": "catalog\/demo\/banners\/iphone6.jpg",         "url": "index.php?route=product\/product&amp;path=57&amp;product_id=49"     },     {         "img": "catalog\/demo\/banners\/macbookair.jpg",         "url": ""     } ] 

i want:

    {         "img": "catalog\/demo\/banners\/iphone6.jpg",         "url": "index.php?route=product\/product&amp;path=57&amp;product_id=49"     },     {         "img": "catalog\/demo\/banners\/macbookair.jpg",         "url": ""     } 

this not valid format of json

{     "img": "catalog\/demo\/banners\/iphone6.jpg",     "url": "index.php?route=product\/product&amp;path=57&amp;product_id=49" }, {     "img": "catalog\/demo\/banners\/macbookair.jpg",     "url": "" } 

you have , separator, separates what? have make array.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -