I'm attempting to retrieve a JSON file and exhibit its components within a div.
Here is the JSON data I have:
[
{
"0":{
"host_id":"129230780",
"host_names":"STK Homes",
"host_since":"2017-05-07T12:45:49Z",
"nb_listings":"2128",
"langues":"['English']",
"localisation":"Londres, Royaume-Uni",
"is_superhost":"False",
"is_viewer_profile_owner":"False",
"reviews_count":"1228",
"url":"https://fr.airbnb.ca/users/show/129230780"
},
"1":{
"host_id":"121683635",
"host_names":"Evolve",
"host_since":"2017-03-20T16:26:31Z",
"nb_listings":"700",
"langues":"['English', 'Espa\u00f1ol', 'Fran\u00e7ais']",
"localisation":"\u00c9tats-Unis",
"is_superhost":"False",
"is_viewer_profile_owner":"False",
"reviews_count":"16495",
"url":"https://fr.airbnb.ca/users/show/121683635"
}
}
]
This is my code. The initial section fetches the JSON data. The subsequent part is intended to showcase the two elements in a div (here I am just printing the outcomes):
fetch(json object)
.then(function (response) {
return response.json();
})
.then(function (data) {
appendData(data);
})
.catch(function (err) {
console.log(err);
});
function appendData(data) {
for (var i = 0; i < data.length; i++) {
console.log(data[0][i].host_id) // retrieves only the first host_id
console.log(data[i][i].host_id) // also retrieves only the first host_id
}
}
Is there a way for me to obtain all the host IDs?