0

I am trying to read a nested JSON message where they key values are incrementing integer values but it does not seem to work.

$.each(data.post, function(entryIndex, entry) {
    $.each(this.entryIndex, function() {
        alert(this.username);
    });
});

Sorry, I tried to paste the JSON code here, but I kept on getting a formatting error. Instead, I have uploaded the JSON here.

2
  • Can we see the JSON you are working with? Are you sure the JSON string has been parsed into an object? Commented Feb 14, 2012 at 5:57
  • Could you provide the json object structure? Maybe some example data that it would contain? Commented Feb 14, 2012 at 5:57

2 Answers 2

1

You went a level too deep:

    $.each(data.posts, function() {

            alert(this.username);

    });​

See here: http://jsfiddle.net/8sb8j/2/

This will get you the usernames of the replies:

    $.each(data.posts, function() {

        $.each(this.replies, function(){
            alert(this.username);
        });

    });​
Sign up to request clarification or add additional context in comments.

Comments

0
$.each(data.posts, function(entryIndex, entry) {
    alert(this.username);
});

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.