【发布时间】:2014-08-28 18:19:52
【问题描述】:
我正在尝试解析这个 json 数据
[
{ "title":"Yorkshire 199/8 * v Durham 237/10",
"link":"http://www.cricinfo.com/ci/engine/match/693421.html?CMP=OTC-RSS",
"description":"Yorkshire 199/8 * v Durham 237/10",
"guid":"http://www.cricinfo.com/ci/engine/match/693421.html"},
{
"title":"Essex v Warwickshire 271/7 *",
"link":"http://www.cricinfo.com/ci/engine/match/693423.html?CMP=OTC-RSS",
"description":"Essex v Warwickshire 271/7 *",
"guid":"http://www.cricinfo.com/ci/engine/match/693423.html"},
{
"title":"Singapore v Malaysia",
"link":"http://www.cricinfo.com/ci/engine/match/774365.html?CMP=OTC-RSS",
"description":"Singapore v Malaysia",
"guid":"http://www.cricinfo.com/ci/engine/match/774365.html"}
]
从服务器端方法返回并使用该方法遍历每个项目
$.ajax({
type: "POST",
url: "Default.aspx/ServerSideMethod",
//data: JSON.stringify({ 'p': 'Sent Text' }),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (data) {
//alert(data.d) //returns the result set displayed above.
$.each(data, function (i, obj) {
alert(obj.title); // returns undefined.
});
},
error: function (x, e) { alert(x.responseText); }
})
但它总是返回未定义的。 我的 jquery 函数或数据有什么问题吗?我的服务器端函数工作正常,上面的 Jquery 函数也显示返回值,但我无法解析这个值。
我也试过这个thread 来解决这个问题,但没有成功。 请任何人...
【问题讨论】:
-
console.log(data);是你所期望的吗? -
我需要在我的网页上显示所有三个项目。这就是为什么我要获取obj.title、obj.description等等...
-
@liaqatali 没关系。
console.log(data)向您展示了什么? -
所以
data不是您在上面发布的内容。解决这个问题,看看你会得到什么。 -
那么这就是你需要迭代的:
$.each(data.d, ...
标签: javascript jquery asp.net json