I want to assign a json object branch
lat
and lng
to a jsonData
variable.
If I console.log jsonData.responseJSON.positions.length
or jsonData.responseJSON.positions[0].lat
, etc
I can see my json data well like this.
console image
But if I code it and run, it has an error.
For example,
var jsonData = $.getJSON("{% static "kia_data_brlatlng.json" %}", function(data){
console.log(jsonData)
});
for(var i = 0; i < jsonData.responseJSON.positions.length; i++) {
//not work
}
for(var i = 0; i < 681; i++) {
//work
}
Someone gave me a tip that it needs a callback function inside the $.getJSON
but still hard to find the solution.
Any help would be appreciated!
I'll add how my json file looks like.
{
"positions": [
{
"branch": "A",
"lat": 37.5221642,
"lng": 127.0339206
},
{
"branch": "B",
"lat": 35.1547587,
"lng": 129.0389295
},
//and 679 more
]
}