I’ve been trying to implement that, but the problem is that in that example, the JSON that is being looped through, the feed for the news, is already an array. My json is just layers of json, and is not an array since I am pulling it down from firebase. How do you loop through the keys of a json? the for loop doesn’t work in the way I am trying.
Here is the json I am trying to parse through
{"\"32cfeb02-eb38-447e-90f5-a7f421531b12\"":{"comments":"Red","fuelType":"Unl","id":"\"32cfeb02-eb38-447e-90f5-a7f421531b12\"","vmake":"Mazda","vmodel":"3","vyear":"2014"},"\"38ce58e2-2b8e-45ca-9180-a9003af7bddf\"":{"comments":":)","fuelType":"Woo","id":"\"38ce58e2-2b8e-45ca-9180-a9003af7bddf\"","vmake":"Doge","vmodel":"Duranho","vyear":"2016"},"\"578abd5c-09b9-4063-88b9-602dda2b17b7\"":{"comments":"Red","fuelType":"Unl","id":"\"578abd5c-09b9-4063-88b9-602dda2b17b7\"","vmake":"Fird","vmodel":"3","vyear":"2014"},"\"837aac36-4745-406d-a6ca-1a4bf58041f1\"":{"comments":"","fuelType":"","id":"\"837aac36-4745-406d-a6ca-1a4bf58041f1\"","vmake":"Ford","vmodel":"Littlecar","vyear":"2010"}}
Here are my two attempts to recreate that example and try to make it work for my json:
fetch(url).then(function(response) {
console.log(JSON.stringify(response));
return response.json();
}).then(function(json) {
var firebaseJson = JSON.stringify(json);
for (var i in firebaseJson.vehicles) {
Context.vehicles.push(new Context.Vehicle(json.vehicles.i));
}
fetch(url).then(function(response) {
console.log(JSON.stringify(response));
return response.json();
}).then(function(json) {
var firebaseJson = JSON.stringify(json);
for (var i in firebaseJson.vehicles) {
Context.vehicles.push(new Context.Vehicle(json.vehicles[1]));
}
And here is that Context.Vehicle function:
function Vehicle(data) {
console.log(data);
this.vyear = data.vyear;
this.vmake = data.vmake;
this.vmodel = data.vmodel;
this.fuelType = data.fuelType;
this.comments = data.comments;
this.id = data.id;
}