I have a PHP file which returns this:
$data = pg_fetch_array($result);
echo json_encode($data);
And in the .js code i do this:
var jsonObj = $.parseJSON(text);
console.dir(jsonObj);
And my problem is I get this “double” data:
{“0″:”3″,”id”:”3″,”1″:”test”,”type”:”test”,”2″:”google”,”name”:”google”, “3”:”http://www.google.com”,”url”:”http://www.google.com”}
Any ideas on how to retrieve it without those indexes (0,1,2…)?
The problem is not in parseJSON method but in pg_fetch_array. And it is the expected behaviour.
PHP Documentation says that pg_fetch_array by default “indexed numerically (beginning with 0) or associatively (indexed by field name)” so you can access values either by index or by name.
To change this behaviour, use either