For some reason my Jquery is not looping through my Json data. Current undefined error.
Json when logged.
{
"cities": [
{
"storename": "new Store",
"notes": "test",
"rejected": "on",
"offer": "test"
}
]
}
Html
console.log(JsonData);
$.each($.parseJSON(JsonData), function(idx, obj) {
alert(obj.storename);
});
3 Answers 3
You don't need to parse your jSON here anymore, so you can use:
$.each(JsonData.cities, function(idx, obj) {
alert(obj.storename);
});
answered Feb 25, 2014 at 9:44
Felix
38.2k8 gold badges46 silver badges56 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
It looks like a object for me, also you need to iterate through the cities property
console.log(JsonData);
$.each(JsonData.cities, function (idx, obj) {
alert(obj.storename);
});
answered Feb 25, 2014 at 9:44
Arun P Johny
389k68 gold badges533 silver badges532 bronze badges
Comments
I was looping through the wrong object, my bad.
$.each($.parseJSON(JsonData), function(idx, cities) {
$.each(cities, function(idx, obj){
console.log(obj.storename)
});
});
answered Feb 25, 2014 at 9:46
Brent
2,50310 gold badges41 silver badges64 bronze badges
Comments
lang-js