大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > C#技巧 > C#反序列化XML及反序列化Model代码

C#反序列化XML及反序列化Model代码

关键词:反序列化XML反序列化Model C#  阅读(760) 赞(16)

[摘要]本文是对什么也不多说,直接贴代码的讲解,对学习C#编程技术有所帮助,与大家分享。

需要反序列的XML

<?xml version='1.0' encoding='utf-8' ?> 
<GetCitiesListResponse>
    <Result Code='000000'>成功</Result> 
    <CitiesList>  
        <City PinYin='ZHANJIANG' HasOutService='N'>湛江</City> 
        <City PinYin='zhangzhou' HasOutService='N'>漳州</City> 
    </CitiesList>
</GetCitiesListResponse>

反序列化Model:

 [XmlRoot("GetCitiesListResponse")]
    public class GetCitiesListResponse
    {
        public Result Result { get; set; }

        [XmlArray("CitiesList"), XmlArrayItem("City")]
        public City[] CitiesList { get; set; }
    }
    public class Result
    {
        [XmlAttribute("Code")]
        public string Code { get; set; }

        [XmlText]
        public string Value { get; set; }
    }

    [XmlRoot("City")]
    public class City
    {
        [XmlAttribute("PinYin")]
        public string PinYin { get; set; }

        [XmlAttribute("HasOutService")]
        public string HasOutService { get; set; }

        [XmlText]
        public string Value { get; set; }
    }


相关评论