gpt4 book ai didi

asp.net - WCF + Json = 错误的序列化

转载 作者:行者123 更新时间:2023-12-01 00:47:07 24 4
gpt4 key购买 nike

为什么采用这个 WCF 3.5 方法

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Json
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public string Upper(string text)
{
return text.ToUpper();
}
}

返回{"d":"TEXT"} ?

它应该返回{"TEXT"}

我正在使用 jQuery 调用。

    $("#upper").click(function() {
$.ajax({
type: "GET",
url: "/Json.svc/Upper?text="+$("#input1").val(),
success: function(data) {
$("#input1").val(data.d);
}
});
});

最佳答案

这是一项安全功能,已添加到 .NET 3.5 中的 JSON 序列化中。它是一个容器对象,因此您只需说 results.d[0],而不是 results[0]。阅读 this article了解更多信息。

关于asp.net - WCF + Json = 错误的序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2186834/

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