I'm having trouble on getting data from a local JSON
file.
I have this peace of code
$.ajax({
method: 'GET',
url: './src/assets/api.json',
success: (function(data) {
$.each(data, function(index, val) {
// Code
console.log('Selling currency: ' + val.eur.pro);
})
}),
error: function() {
console.log('Something went wrong.');
}
})
That throws an error in console:
Cannot read property 'pro' of undefined
My JSON file looks like this
{
"result": {
"date": "23.08.2017",
"eur": {
"kup": "119.0352",
"sre": "119.3934",
"pro": "119.7516"
},
"usd": {
"kup": "101.2032",
"sre": "101.5077",
"pro": "101.8122"
},
// other objects ...
}
}
I don't know why is it throwing that error. If I were to remove the pro
from the val.eur.pro
and leave it like this val.eur
it returns the object just fine. I don't know how am I suppose to access the 3rd value.