如何验证空间,同时在WCF中的json序列化休息完整的sericves [英] how to validate the spaces while json serialization in WCF rest full sericves
问题描述
我有一个班级
[DataContract]
公共班级测试
{
[DataMember(EmitDefaultValue = false)]
public string test1 {get;组; }
[DataMember(EmitDefaultValue = false)]
public string testA {get;组; }
[DataMember(EmitDefaultValue = false)]
public string testB {get;组; }
}
我有一个界面
[OperationContract]
[FaultContract(typeof(CustomException))]
[WebInvoke(Method =POST,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate =SaveAliasOfEndPoints)]
bool Mymethod(测试objtesting);
和我有这样的实现
public bool Mymethod(测试objtesting)
{
返回true;
}
{
test1 :XXX,
testA:XXX,
testB:XXX
}
现在问题在这里
当我用参数test1发布json时它最后有空格
现在json是解析为我的类在test1的代码中测试值为null
这是错误的。我想抓住这个空间并抛出用户定义的错误。
请帮助我这个
提前感谢
推荐答案
忽略json标准中的空格,除非它们在引号中(字符串部分)。
test1和test1是json解析器的两个不同的东西,第二个不是由你给出的类定义中的json序列化器生成的。
White spaces in the json standard are ignored unless they are in quotes (the string part).
"test1" and "test1 " are two different things for the json parser, and the second will not be generated by json serializer from the class definition you have given.
这篇关于如何验证空间,同时在WCF中的json序列化休息完整的sericves的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!