I'm trying to put my data into Json format. The code seems to work fine, I get a Json format, but the data is not Json valid. This is how the json comes out:
({
"sample": [
{
"0": "12",
"image_id": "12",
"1": "background.JPG",
"path": "background.JPG",
"2": "background.JPG",
"name": "background.JPG",
"3": "image\/jpeg",
"type": "image\/jpeg",
"4": "51600",
"size": "51600",
"5": "4",
"likes": "4",
"6": "zwitserland",
"onderwerp": "zwitserland",
"7": "Landscape from cableway",
"beschrijving": "Landscape from cableway"
},
{
"0": "13",
"image_id": "13",
"1": "IMG_1052.JPG",
"path": "IMG_1052.JPG",
"2": "IMG_1052.JPG",
"name": "IMG_1052.JPG",
"3": "image\/jpeg",
"type": "image\/jpeg",
"4": "45434",
"size": "45434",
"5": "28",
"likes": "28",
"6": "belgium",
"onderwerp": "belgium",
"7": "Highway in Belgium",
"beschrijving": "Highway in Belgium"
}, ETC ETC
This is my php code. When I put my code into a Json editor I get the following error:
Parse error on line 1: ({ "sample": [ ^ Expecting '{', '['
$arr = array();
$rs = mysql_query("SELECT * FROM images");
while($obj = mysql_fetch_array($rs)) {
$arr[] = $obj;
}
$json = '{"sample":'.json_encode($arr).'}';
echo $_GET['jsoncallback'] . '(' . $json . ')';