小编Thi*_*hat的帖子

C#中XML列表对象的反序列化

我试图在C#中反序列化xml,看起来像这样(缩短版本):

<?xml version="1.0" encoding="UTF-8"?>
<map>
    <parts>
      <part name="default part">
        <objects count="1597">
            <object type="1" symbol="6">
                <coords count="130">
                    <coord x="-221595" y="-109687" flags="1"/>
                    <coord x="-221625" y="-109744"/>
                    <coord x="-221640" y="-109785"/>
                    <coord x="-221640" y="-109841" flags="1"/>
                    <coord x="-221655" y="-109969"/>
                    <coord x="-221655" y="-110040"/>
                    <coord x="-221640" y="-110164" flags="1"/>
                    <coord x="-221640" y="-110209"/>
                    <coord x="-221655" y="-110265"/>
                </coords>
                <pattern rotation="0">
                    <coord x="0" y="0"/>
                </pattern>
            </object>
          </objects>
        </part>
   </parts>
</map>
Run Code Online (Sandbox Code Playgroud)

使用以下类:

[XmlRoot("map")] 
public class Map {


    [XmlElement(ElementName = "parts")]
    public List<Part> parts { get; set; }

    public Map()
    {
         parts = new …
Run Code Online (Sandbox Code Playgroud)

c# xml serialization

2
推荐指数
1
解决办法
356
查看次数

标签 统计

c# ×1

serialization ×1

xml ×1