I want to transform a JSON object into an array.
Am using a PHP script to create a JSON file using this code:
$stores = array();
$i=0;
$reponse = $bdd->query('select * from store ');
while ($donnees = $reponse->fetch())
{
$stores[$i] = $donnees;
$i++;
}
var_dump($stores);
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($stores));
fclose($fp);
In my JS file am using this code to load the data:
var json_obj = $.getJSON("results.json", function (data) {
json_obj = data;
return json_obj;
});
alert(JSON.stringify(json_obj));
Now I want to transform my JSON object into a JavaScript array. But in specific way:
var props=[] ;
props.push({title:json_obj[0].name,Data:json_obj[0].Description});
props.push({title:json_obj[1].name,Data:json_obj[1].Description});
$.each(props, function (i,v)
{
console.log(i,v);
});