vendredi 29 août 2014

Add field to a JSON file


Vote count:

0




I have a very simple JSON file "json.txt" :



{
"status": true,

"data":
{
"clics":
[
{
"id": "1",
"title": "Title 1",
"comment": "Blablabla 1",
"url": "http://photostodisplay/1.jpg"
},
{
"id": "2",
"Title": "Title 2",
"comment": "Blablabla 2",
"url": "http://photostodisplay/2.jpg"
}
]
}
}


and I would like to add data and get the following result :



{
"status": true,

"data":
{
"clics":
[
{
"id": "1",
"title": "Title 1",
"comment": "Blablabla 1",
"url": "http://photostodisplay/1.jpg"
},
{
"id": "2",
"Title": "Title 2",
"comment": "Blablabla 2",
"url": "http://photostodisplay/2.jpg"
},
{
"id": "3",
"Title": "Title 3",
"comment": "Blablabla 3",
"url": "http://photostodisplay/3.jpg"
}
]
}
}


The php code I use return the following error :


Fatal error: Cannot use object of type stdClass as array in /home/mitinux/www/clic/test.php on line 10


I understand the error but I don't know how to remediate to it...


Any ideas ? Thanks.



asked 31 secs ago







Add field to a JSON file

Aucun commentaire:

Enregistrer un commentaire