gpt4 book ai didi

javascript - 如何循环 jquery 返回的 JSON 数据?

转载 作者:数据小太阳 更新时间:2023-10-29 04:39:20 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How do I return JSON and loop through the returned json in jQuery in MVC app?

这是我的 MVC Controller 返回的数据,我在成功回调中得到了这个:

[{ "_id" : { "$oid" : "4dc8" }, "eid" : { "$oid" : "4da" }, "user" : "bob", "text" : "First comment!!", "dt" : { "$date" : 1304966277978 } }, 
{ "_id" : { "$oid" : "4dc8" }, "eid" : { "$oid" : "4da" }, "user" : "bob", "text" : "Second comment!!", "dt" : { "$date" : 1304966347677 } },
{ "_id" : { "$oid" : "4dc8" }, "eid" : { "$oid" : "4da" }, "user" : "bob", "text" : "Third comment!!", "dt" : { "$date" : 1304966493240 } }
]

Controller :

[HttpGet]
public JsonResult GetComments(params...)
{
return Json(new { comments = GetFromDB().ToJson() }, JsonRequestBehavior.AllowGet);
}

问题:我尝试了几种循环行的方法。但一切似乎都是无限循环。

$.ajax(
{
type: "GET",
url: "/comment/GetComments",
dataType: "json",
data: "app=" + app + "&eid=" + eid + "&pg=" + pg + "&pgs=" + pgs,
success: function (result) {
$.each(result[comments], function () {
$.each(this, function (k, v) {
alert('this a column or attribute');
});
alert('end of row');
});
},
error: function (req, status, error) {
alert('Error=' + error + ' & Status=' + status);
}
});

还试过:

$.each(result["comments"], function (key, value) {
alert('comment found');
});

如何循环行并访问每个属性的值?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com