2011-05-19 149 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