gpt4 book ai didi

jquery - 使用 JQuery 读取 JSON

转载 作者:行者123 更新时间:2023-12-01 08:27:44 25 4
gpt4 key购买 nike

我正在使用 JQuery 在 Web 服务中执行操作。将数据写回数据库后,该服务会返回 JSON 响应。我的请求如下所示:

$.ajax({
url: "/services/myService.svc/PostMessage",
type: "POST",
contentType: "application/json; charset=utf-8",
data: '{"message":"testing","comments":"test"}',
dataType: "json",
success: function (response) {
if ((response.d != null) && (response.d.length > 0)) {
// Parse the status code here
}
else { alert("error!"); }
},
error: function (req, msg, obj) {
alert("error: " + req.responseText);
}
});

当我的响应返回时,response.d 包含以下内容:

[{"StatusCode":1}]

如何解析 StatusCode 的值?

最佳答案

这是一个包含具有 StatusCode 属性的对象的数组。

你可以这样写

alert(response.d[0].StatusCode)

关于jquery - 使用 JQuery 读取 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2508394/

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