我有一个包含数据的测试 xml 文件,并使用适当的属性设置我的对象。我没有收到任何错误,但在反序列化后没有任何对象返回数据。谢谢你的帮助。
[DataContract(Name = "level1", Namespace = "")]
public class Level1
{
[DataMember(Name = "level2")]
public Level2 Level2{get;set;}
}
[DataContract(Name = "level2", Namespace = "")]
public class Level2
{
[DataMember(Name = "code")]
public string Code{get;set;}
[DataMember(Name = "global")]
public string Global{get;set;}
}
//Desrilizing Data
DataContractSerializer dcs = new DataContractSerializer(typeof(Level1));
FileStream fs = new FileStream("ExampleData/Example.xml", FileMode.OpenOrCreate);
XmlDictionaryReader reader =
XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
Level1 p = (Level1)dcs.ReadObject(reader);//Coming back but with no values
XML
<?xml version="1.0" encoding="utf-8" ?>
<level1>
<level2 code="332443553" global="21332"/>
</level1>