我正在使用 JQuery 调用我的 WCF 服务。响应正文显示了我的 JSON 格式数据,但我不确定如何解析它。请参阅我的代码,了解我到目前为止所做的事情。
$.ajax({
url: "http://wks52025:82/WcfDataService.svc/GetNotes()?$format=json",
type: "get",
datatype: "json",
success: function (data) {
$.each(data, function(i, item) {
alert(data[i].Title);
})
}
});
});
这是我的 JSON
{
"d": [
{
"__metadata": {
"id": "http://wks52025:82/WcfDataService.svc/tblNotes(guid'93629a5f-2bb3-4190-b876-3d8a2997e76a')",
"uri": "http://wks52025:82/WcfDataService.svc/tblNotes(guid'93629a5f-2bb3-4190-b876-3d8a2997e76a')",
"type": "GenesisOnlineModel.tblNote"
},
"NotesID": "93629a5f-2bb3-4190-b876-3d8a2997e76a",
"NotesTitle": "BSKYB",
"NotesText": "new Director of Brand and Media ",
"ParentID": 8879,
"ContactID": 309,
"JobID": 1000088150,
"UserID": "8b0e303a-68aa-49a5-af95-d994e2bdd5ac",
"GroupID": null,
"RelatedType": "Advertiser Contact",
"IsShared": true
},
{
"__metadata": {
"id": "http://wks52025:82/WcfDataService.svc/tblNotes(guid'0f21866b-4a5c-417f-afe1-70ffbd1ce1f3')",
"uri": "http://wks52025:82/WcfDataService.svc/tblNotes(guid'0f21866b-4a5c-417f-afe1-70ffbd1ce1f3')",
"type": "GenesisOnlineModel.tblNote"
},
"NotesID": "0f21866b-4a5c-417f-afe1-70ffbd1ce1f3",
"NotesTitle": "BSKYB More",
"NotesText": "Contacted all major contacts on this profile",
"ParentID": 8879,
"ContactID": null,
"JobID": null,
"UserID": "8b0e303a-68aa-49a5-af95-d994e2bdd5ac",
"GroupID": null,
"RelatedType": "Advertiser",
"IsShared": true
}
]
}
在我的成功功能代码块中,我的警报中未定义。任何帮助都会很棒。
最佳答案
关闭!在成功 block 中,执行以下操作:
success: function (data) {
$.each(data.d, function(i, item) {
alert(item.NotesTitle);
})
}
更新:实现@Johans 评论。
关于jquery - 使用 JQuery 解析此 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16523709/