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?