WCF +的Json =系列化错误 [英] WCF + Json = wrong serialization
本文介绍了WCF +的Json =系列化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这个WCF 3.5方法
[的ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)
公共类的Json
{
[OperationContract的]
[WebGet(ResponseFormat = WebMessageFormat.Json)
公共字符串上(字符串文本)
{
返回text.ToUpper();
}
}
收益 {D:TEXT}
这应该返回 {TEXT}
我使用jQuery调用。
$(#上)。点击(函数(){
$阿贾克斯({
键入:GET,
网址:/Json.svc/Upper?text =+ $(#输入1)VAL()。
成功:功能(数据){
$(#输入1)VAL(data.d)。
}
});
});
解决方案
这是一个已经被添加到JSON序列化在.NET 3.5的安全功能。这是一个容器对象,所以不是,比方说,结果[0]
,你刚才说 results.d [0]
。阅读本文更多信息。
Why this WCF 3.5 method
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Json
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public string Upper(string text)
{
return text.ToUpper();
}
}
returns {"d":"TEXT"}
?
It should returns {"TEXT"}
I'm calling using jQuery.
$("#upper").click(function() {
$.ajax({
type: "GET",
url: "/Json.svc/Upper?text="+$("#input1").val(),
success: function(data) {
$("#input1").val(data.d);
}
});
});
解决方案
This is a security feature that has been added to the JSON serialization in .NET 3.5. It's a container object, so instead of, say, results[0]
, you would just say results.d[0]
. Read this article for more information.
这篇关于WCF +的Json =系列化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文