Javascript 在JSON上迭代时出现问题
我有JSON:Javascript 在JSON上迭代时出现问题,javascript,jquery,json,Javascript,Jquery,Json,我有JSON: { "GetCommentsByPostResult": [ { "CommentCreated": "\\/Date(1305736030505+0100)\\/", "CommentText": "Comment 1" }, { "CommentCreated": "\\/Date(1305736030505+0100)\\/",
{
"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个带有“undefined”的警报屏幕……不知道为什么会有人知道?因为的回调(在数组上调用时)中的第一个参数是数组中的索引 这应该起作用:
$.each(data.GetCommentsByPostResult, function(index, element) {
alert(element.CommentText);
});
因为的回调中的第一个参数(在数组上调用时)是数组的索引 这应该起作用:
$.each(data.GetCommentsByPostResult, function(index, element) {
alert(element.CommentText);
});
惊人,本应更仔细地阅读文档,但耶,好,仍在学习:-)将勾选为答案惊人,本应更仔细地阅读文档,但耶,好,仍在学习:-)将勾选为答案