小编Tor*_*ter的帖子

遍历对象数组

我有一个像这样的JSON字符串

 var json =  '{ "Comments": 
    [
      { "Id" : 1,"Comment" : "Test comment","Name" : "Yogesh","Child" : 0},
      { "Id" : 2,"Comment" : "Test comment II","Name" : "Yogesh","Child" : 0}
    ] 
    }';
Run Code Online (Sandbox Code Playgroud)

我正在尝试遍历这样的对象:

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/>";
}
Run Code Online (Sandbox Code Playgroud)

但是在这里commentfor循环变成了0并且1 …

javascript jquery

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×1

jquery ×1