0

I cant get that to work:

My json

[{"myicons":[{"icon":[{"rel":"1","id":"icon1","class":"bookmark desktop-icon ui-draggable","title":"bookmark1"}]},{"icon":[{"rel":"2","id":"icon2","class":"bookmark desktop-icon ui-draggable","title":"bookmark2"}]}]}]

My jquery each function finds the 2 icons but i cant seem to get the values... it keeps saying undefined.

var myicons = data[0].myicons;
            $.each(myicons, function() {

                var iconid = this.id;
                alert(iconid);
});

1 Answer 1

2

Your JSON is full of array. i,e. data, myicons and even icon

$.each(data, function () {
    var myicons = this.myicons;
    $.each(myicons, function () {
        var iconid = this.icon[0].id;
        alert(iconid);
    });
});

DEMO

I strongly suggest you to simplify yous JSON object

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

5 Comments

@MartijnMichel, As I have said your JSON is full of array. See formatted JSON object you will understand. If you have problem ping me
hmm actually when i remove the first each it still works. thanks for helping me out!
ah ok,, because then each icon is an object inside the array icons. thanks!
@MartijnMichel, You got it mate
Thanks i changed my json file and yes much easier to find the values! ;)

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.