2011-05-19 109 views
0

我有JSON:问题遍历JSON

{ 
    "GetCommentsByPostResult": [ 
     { 
      "CommentCreated": "\\/Date(1305736030505+0100)\\/", 
      "CommentText": "Comment 1" 
     }, 
     { 
      "CommentCreated": "\\/Date(1305736030505+0100)\\/", 
      "CommentText": "Comment 2" 
     }, 
     { 
      "CommentCreated": "\\/Date(1305736030505+0100)\\/", 
      "CommentText": "Comment 2" 
     } 
    ] 
} 

而且我试着使用过它遍历此:

$.each(data.GetCommentsByPostResult, function (e) { 
         alert(e.CommentText); 
        }); 

但所有即时得到3个警报屏幕,在它“未定义” ....不知道为什么有人知道?

回答

6

因为$.each的回调(在数组上调用时)中的第一个参数是数组中的索引。

这应该工作:

​​
+2

惊人,应该已经阅读文档有点更加紧密,但耶OK还在学习:-)会勾出答案 – Exitos 2011-05-19 08:33:21