本文介绍了WCF DataContract数据成员的订单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是从按字母顺序排列创建了DataContract创建的XML。我有一个DataContract类定义为:
Is the xml that is created from your DataContract created in alphabetical order. I have a DataContract class defined as:
[DataContract(Name = "User", Namespace = "")]
public class User
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public string Email { get; set; }
[DataMember]
public string Password { get; set; }
}
当我做了下面的帖子:
<User>
<FirstName>abc</FirstName>
<LastName>123</LastName>
<Email>[email protected]</Email>
<Password>pass</Password>
</User>
当我做了我的帖子后,GET和返回JSON作为结果,电子邮件是空的,但如果我发布我的XML为:
When I did a GET after my post and returned the result as JSON, email was null, but if I POST my xml as:
<User>
<Email>[email protected]</Email>
<FirstName>abc</FirstName>
<LastName>123</LastName>
<Password>pass</Password>
</User>
电子邮件不再是空当我做了GET并返回为JSON。为什么要这样做呢?
Email is no longer null when I do a GET and return it as JSON. Why is it doing this?
推荐答案
与装饰它在订单参数在DataMemberAttribute类:
decorate it with the Order Parameter in the DataMemberAttribute class:
[DataMember(Order = index)]
在串行反射所说的字母顺序。
除非当装饰是这样的:
The reflector in the serializer puts it alphabetically.Unless when decorated like this:
[DataMember(Order = 0)]
public string FirstName { get; set; }
[DataMember(Order = 1)]
public string LastName { get; set; }
[DataMember(Order = 2)]
public string Email { get; set; }
[DataMember(Order = 3)]
public string Password { get; set; }
这篇关于WCF DataContract数据成员的订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!