像这样反序列化 xml 的最简单方法是什么:
<root>
<item id="1"/>
<item id="2"/>
<item id="3"/>
</root>
最佳答案
实际上,这是可能的-答案here显示如何。只需将属性定义为数组,但使用 XmlElement
public class Item
{
[XmlAttribute("id")]
public int Id { get ;set; }
[XmlText]
public string Name { get; set; }
}
[XmlRoot("root")]
public class Root
{
[XmlElement("item")]
public Item[] Items { get;set;}
}
关于C# xml内联数组反序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14768918/