Hi all,
I recently started a project where i want to do some aninmations with weather data. However i got stuck rather quickly and can’t seem to acces my JSON.
I looked everywhere and tried a lot but the answer still eludes me.
After yet another hour of wondering stackoverflow, MDN and various other resources I set my hopes on your vast knowledge.
Topic:
I have JSON data formatted like so:
[
{
"id": 2613357,
"name": "Smidstrup",
"country": "DK",
"coord": {
"lon": 12.55787,
"lat": 55.865688
}
},
{
"id": 6460975,
"name": "Rastnik",
"country": "BG",
"coord": {
"lon": 25.283331,
"lat": 41.400002
}
},
{
"id": 727762,
"name": "Rastnik",
"country": "BG",
"coord": {
"lon": 25.283331,
"lat": 41.400002
}
},
{
"id": 596826,
"name": "Murava",
"country": "LT",
"coord": {
"lon": 23.966669,
"lat": 54.916672
}
}
]
I load it in like so and it appears as an object:
cities = loadJSON('city.list.test.json');
console.log(cities);
When I try to access a single city it tells me the value is undefined or that I use disallowed characters
From here on I tried numerous things and thought of scandalous means to get access (like treating it the objects as an array and loading in my object in an array (with the vague hope of it being usefull)), Also i tried various object properties like object.keys and object.values but didn’t get me where I needed to be.
Although it seems likely to me that I need to access the object within the object I have run out of ideas how to go about doing so.
A push in the right direction would be much appreciated.