使用jQuery循环JSON

使用jQuery循环JSON,jquery,ajax,json,Jquery,Ajax,Json,我有一个标准的AJAX请求: $.ajax({ type: "POST", contentType: "application/json;", ..., success: function(data){ // Wanna loop the resultList here... } }); …返回一个JSON对象,如下所示: { "notification": "Search complete", "resultList": [ {

我有一个标准的AJAX请求:

$.ajax({
  type: "POST",
  contentType: "application/json;",
  ...,
  success: function(data){

    // Wanna loop the resultList here...

  }
});
…返回一个JSON对象,如下所示:

{
   "notification": "Search complete",
   "resultList": [
      {
         "id": 1,
         "comment": "lorem"
      },
      {
         "id": 2,
         "comment": "ipsim"
      },
      {
         "id": 3,
         "comment": "dolor"
      }
   ]
}
如何使用jQuery循环执行此操作,以便在日志中打印以下内容:
ID#1-lorem
ID#2-同侧脸
ID#3-多洛


很抱歉发布了另一个通知,但我不知道如何在不包含通知的情况下打印此通知。希望这也能帮助其他人。

非常简单,您有一个对象数组:

for (var i = 0; i < data.resultList.length; i++) {
    console.log(data.resultList[i].id);
}
for(var i=0;i
既然你问jQuery的答案,这里有一个只是为了好玩:

$.each(foo.resultList, function(i, item) {
    console.log('ID #' + item.id + ' - ' + item.comment);
});

谢谢我一直认为我应该使用。每一个都很好用。作为参考(为了得到我想要的东西),它应该像:
console.log('ID#'+data.resultList[I].ID+'-'+data.resultList[I].comment)将其更改为可接受的答案,因为在这种情况下我更喜欢jQuery。