I have a little problem with Jquery getJSON function.
my json here
{ "entries": [
{
"type": "status",
"SID": "X999_Y999",
"from": {
"name": "Tom Brady",
"id": "X12"
},
"message": "Json message no 1! ",
"actions": {
"UP_link": "123456",
"Comment_link": "7891011"
},
"created_time": "2010-08-02T21:27:44+0000",
"Comments": [
{
"CID": "1234",
"name": "Tom Brady",
"UID": "1234",
"Text": "My comment",
"when_comment": "2010-08-02T21:27:44+0000"
},
{
"CID": "1234",
"name": "Tom Brady",
"UID": "1234",
"Text": "My comment",
"when_comment": "2010-08-02T21:27:44+0000"
}
]
}
] }
I used this to read
$.getJSON('json4test.json',
function(data) {
$.each(data.entries, function(entryIndex, entry) {
var html = '<li class="top-level">name=' + this.from.name +', comment = '+this.Comments.Text+ '</li>';
$("#results").append(html);
});
});
I actually can read array of this.from.name, but why the result of reading this.Comments.Text is “undefined”.
How can I read this one properly?
this.Comments.Textis an array, so you would need to loop through that as well.Inside the loop you can access the
Textproperty of each comment. See the example on jsbin (check the console for output).