我有一个返回这个 json 数据的 web 方法:
{
"TotalItems":25,
"Assets":
[
{"Id":"49c1fc23-edab-4087-bf3b-884b16399e4b"},
{"Id":"5f8f5aaa-dcfa-4a3f-ae21-b7a9683551e5"},
{"Id":"f589f567-c4d0-49e8-acf4-d3dcd1813b4d"},
{"Id":"b5678b13-1d07-4be5-9c70-02f8475de771"}
]
}
这是我的 ajax 调用和数据返回时调用的方法。
$.ajax({
type: "POST",
url: "/Services.asmx/GetAssets",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(results) {
alert(results["d"]); // alerts json above
alert(results.d); // alerts json above
// all of these alert "undefined"
alert(results["d"]["TotalItems"]);
alert(results["d"].TotalItems);
alert(results.d["TotalItems"]);
alert(results.d.TotalItems);
}
});
如何访问 json 结果中的数据?