我想要反序列化以下XML...
<MyType>
<Items>
<ItemSum>
<Value>3</Value>
</ItemSum>
<Item>
<Value>1</Value>
</Item>
<Item>
<Value>2</Value>
</Item>
</Items>
</MyType>
将其转换为以下结构类型...
[XmlRoot("MyType")]
public class MyType
{
[XmlArray("Items")]
[XmlArrayItem("Item")]
public CItems Items { get; set; }
public class CItems : List<CItem>
{
[XmlElement("ItemSum")]
public CItem ItemSum { get; set; }
}
public class CItem
{
[XmlElement("Value")]
public int Value { get; set; }
}
}
然而,如果我尝试使用C#的XmlSerializer
这样做,ItemSum
属性总是null
。您有什么想法我做错了什么吗?
MyType
类中有CItem
和CItems
两个类? - Rui JarimbaMyType
的结构进行更改。 - Good Night Nerd Pride