1)首先声明测试类如下:
[DataContract(Name = "StudentName")]
class Student
{
[DataMember]
public string Name { get; set; }
[DataMember]
public int Age { get; set; }
[DataMember]
public string Address { get; set; }
}
构建对象:
2)Student stu = new Student() { Name = "张三", Address = "测试地址", Age = 20 };
3)使用DataContractSerializer得出XML接口如下:
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/TongCheng.Interface.FlightInter.Ctrip">
测试地址
20
张三
* 注意序列化出来的属性顺序
4)手动调整XML节点顺序至如下状态:
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/TongCheng.Interface.FlightInter.Ctrip">
20
张三
测试地址
5)再使用DataContractSerializer反序列化4步骤的XML,实体信息如下:
对象的Address属性值去哪里了?
很疑惑,希望知道的朋友告诉下,在线等,不胜感激。
自己顶下,等大牛。~~~~
写个构造函数把值在NEW的时候直接附上。
public Student(string Name, int Age, string Address){ this.Name = Name; this.Age = Age; this.Address = Address;}
你那种是否因为位置前后不一造成没有输入,有没有试
是否要专从:对象成员出现的顺利和在Type定 义的顺序一致
既然有Name,没有道理没有Address,重新编译下你的项目看看
MySQL server error report:Array ( [0] => Array ( [message] => MySQL Query Error ) [1] => Array ( [sql] => INSERT INTO my4517906
.p_sessions
(sesskey, expiry, ip, data) VALUES ('e382af22803911533ae345c106608252', '1431692019', '125.82.10.137', 'a:0:{}') ) [2] => Array ( [error] => Table 'my4517906.p_sessions' doesn't exist ) [3] => Array ( [errno] => 1146 ) )
@CodeofWorker
使用DataContractSerializer 不显示指定Order顺序时序列化出XML的结果对比。
顶顶顶,继续等大牛。