我有一个这样的 JSON 字符串
var json = '{ "Comments":
[
{ "Id" : 1,"Comment" : "Test comment","Name" : "Yogesh","Child" : 0},
{ "Id" : 2,"Comment" : "Test comment II","Name" : "Yogesh","Child" : 0}
]
}';
我正在尝试像这样迭代对象:
var parsedJSON = $.parseJSON(json);
var html = "";
for (comment in parsedJSON.Comments) {
html += "Id: " + comment.Id;
html += "Comment: " + comment.Comment;
html += "Name: " + comment.Name;
html += "Child: " + comment.Child;
html += "<br/>";
}
但是comment
在 for 循环中,我的意思不是一个对象,0
而1
只是一个字符串,我如何迭代这个数组?