0

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

2

You don't need to parse your jSON here anymore, so you can use:

$.each(JsonData.cities, function(idx, obj) {
     alert(obj.storename);
});

Fiddle Demo

Sign up to request clarification or add additional context in comments.

Comments

2

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);
});

Comments

0

I was looping through the wrong object, my bad.

 $.each($.parseJSON(JsonData), function(idx, cities) {
                          $.each(cities, function(idx, obj){
                           console.log(obj.storename)
                          });
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.