2014-02-25 145 views
0

由于某种原因,我的Jquery没有循环浏览Json数据。当前未定义的错误。Json jquery每个循环

Json登录时。

{ 
    "cities": [ 
     { 
      "storename": "new Store", 
      "notes": "test", 
      "rejected": "on", 
      "offer": "test" 
     } 
    ] 
} 

的Html

console.log(JsonData); 

$.each($.parseJSON(JsonData), function(idx, obj) { 
     alert(obj.storename); 
}); 

回答

2

你并不需要解析您的jSON在这里了,所以你可以使用:

$.each(JsonData.cities, function(idx, obj) { 
    alert(obj.storename); 
}); 

Fiddle Demo

+0

谢谢,真的很好的答案 – Brent

+0

很高兴帮助!快乐编码伴侣:) – Felix

2

它看起来像我的一个对象,你也需要通过城市的房地产迭代

console.log(JsonData); 

$.each(JsonData.cities, function (idx, obj) { 
    alert(obj.storename); 
}); 
0

我是通过错了对象循环,是我不好。

$.each($.parseJSON(JsonData), function(idx, cities) { 
          $.each(cities, function(idx, obj){ 
          console.log(obj.storename) 
          }); 
    });