zoukankan      html  css  js  c++  java
  • 开发Tips—Deserialize Xml


     

    View Code
     /// <summary>
        /// 归属地查询响应
        /// </summary>
        [Serializable]
        [XmlRoot(Namespace = "http://api.showji.com/Locating/", ElementName = "QueryResponse")]
        public class QueryResponse
        {
            /// <summary>
            /// 手机号
            /// </summary>
            [XmlElement("Mobile")]
            public string Mobile
            {
                get;
                set;
            }
            /// <summary>
            /// 查询结果,bool值
            /// </summary>
            [XmlElement("QueryResult")]
            public string QueryResult
            {
                get;
                set;
            }
            /// <summary>
            /// 归属地省份
            /// </summary>
            [XmlElement("Province")]
            public string Province
            {
                get;
                set;
            }
            /// <summary>
            /// 归属地城市
            /// </summary>
            [XmlElement("City")]
            public string City
            {
                get;
                set;
            }
            /// <summary>
            /// 归属地区号
            /// </summary>
            [XmlElement("AreaCode")]
            public string AreaCode
            {
                get;
                set;
            }
            /// <summary>
            /// 归属地邮编
            /// </summary>
            [XmlElement("PostCode")]
            public string PostCode
            {
                get;
                set;
            }
            /// <summary>
            /// 运营商
            /// </summary>
            [XmlElement("Corp")]
            public string Corp
            {
                get;
                set;
            }
            /// <summary>
            /// 卡制式
            /// </summary>
            [XmlElement("Card")]
            public string Card
            {
                get;
                set;
            }
        }
    View Code
     /// <summary>
            /// 手机号归属地信息
            /// </summary>
            /// <param name="num"></param>
            /// <returns></returns>
            private QueryResponse MobileInfo(string num)
            {
                string uri = string.Format(string.Format("http://api.showji.com/Locating/zhoumoyukuai.aspx?m={0}&output=xml&callback=querycallback", num));
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(uri);
                XmlNode node = xmlDoc.DocumentElement.ParentNode;
                //Xml序列化
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(QueryResponse));
                QueryResponse query = (QueryResponse)xmlSerializer.Deserialize(new XmlNodeReader(node));
                return query;
            }

    自己学习记录,仅供参考。

  • 相关阅读:
    Netty之ProtoBuf(六)
    Netty对WebSocket的支持(五)
    Netty之心跳检测技术(四)
    Netty之多用户的聊天室(三)
    Docker Compose 笔记
    vue.js学习笔记
    powerdesigner 生成C#code 实体 模板设备
    .net 接收post 的参数 加载xml
    powerdesigner 生成实体代码 附加生成xml
    PostgreSql 获取所有的表、视图、字段、 主键
  • 原文地址:https://www.cnblogs.com/shiyix/p/Tips.html
Copyright © 2011-2022 走看看