Reputation: 1477
im having problems in getting the data inside my json file, it says "undefined". Im trying to get the data from the "key" parameter.
Json Structure:
{
"list":[
{
"key":"12 ano",
"value":"12 ano"
},
{
"key":"12 ano administrativo",
"value":"12 ano administrativo"
}
]
}
Here is the code:
$.getJSON('what.json', function(data){
$.each(data, function(i, value){
console.log(value.key);
})
});
Upvotes: 1
Views: 35
Reputation: 289
Use This
$.getJSON( "ajax/test.json", function( data ) {
var items = [];
$.each( data, function( key, val ) {
alert(val);
alert(key);
});
Upvotes: -1
Reputation: 36703
Iterate inside data.list
array
$.getJSON('what.json', function(data){
$.each(data.list, function(i, value){
console.log(value.key);
})
});
Upvotes: 1
Reputation: 133403
You need to iterate data.list
, You are getting the error as your JSON doesn't have key
at top level
$.each(data.list, function(i, value){
console.log(value.key);
});
Upvotes: 1