Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-24-2011, 04:20 PM   PM User | #1
doforumda
New Coder

 
Join Date: Oct 2009
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
doforumda is an unknown quantity at this point
how to get json data using jquery

How can I get the comments from below json data?

Code:
{
"data":
[
    {
        "id":"123",
        "from":{"name":"name","id":"12"},
        "message":"Message",
        "comments": {
                        "data":
                        [
                            {
                                "id":"342",
                                "from":{"name":"name","id":"32"},
                                "message":"comment message 1"
                            },
                            {
                                "id":"341",
                                "from":{"name":"name","id":"21"},
                                "message":"comment message 2"
                            }
                        ],
                        "count":2
                    }
    },
    {
        "id":"143",
        "from":{"name":"name","id":"52"},
        "message":"Message",
        "comments": {
                        "data":
                        [
                            {
                                "id":"362",
                                "from":{"name":"name","id":"72"},
                                "message":"comment message 1"
                            },
                            {
                                "id":"341",
                                "from":{"name":"name","id":"41"},
                                "message":"comment message 2"
                            }
                        ],
                        "count":2
                    }
    }
]
}
I know how to get id, from and message. but I do not know how can I get data inside comments.

here is my jquery code

Code:
$.getJSON(newsfeed_url,function(d) {
    $.each(d.data, function(i,res) {
        html += "<div class='container'>";
        html += "<li>"+ res.from.name +"</li>";
        html += "<li class='message'>" + res.message + "</li>";
        html += "<li>Comments: " + res.comments.count + "</li>";

        $.each(res.comments.data, function(i, comment) {
            html += "<li class=''>" + comment.message + "</li>";
        });
        html += "</div>";            
    });
    html += "</ul>";
    $("#contents").html(html);
});
my current code does get res.from.name, res.comments.count but it does not get data inside comments i.e. res.comments.data.

how can I achieve it?

Last edited by doforumda; 09-24-2011 at 04:22 PM..
doforumda is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:41 AM.


Advertisement
Log in to turn off these ads.