zoukankan      html  css  js  c++  java
  • C# 解析XML格式的字符串

     public CreateOrderReturnResult GetCreateOrderReturnApi()
            {
                var result = new CreateOrderReturnResult();
                try
                {
                    DataSet ds = new DataSet();
                    StringReader stream = new StringReader("XML字符串");//读取字符串为数据量
                    XmlTextReader reader = new XmlTextReader(stream);//对XML的数据流的只进只读访问
                    ds.ReadXml(reader);//吧数据读入DataSet
                    DataTable dt = ds.Tables["createOrderReturn"];
    
                    result.Orders = new List<CreateOrderReturn>();
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            CreateOrderReturn order = new CreateOrderReturn();
                            DataRow dr = ds.Tables[0].Rows[i];
                            order.AdditionalDocument = dr["additionalDocument"].ToString();
                            order.DeliveryCharge = decimal.Parse(dr["deliveryCharge"].ToString());
                            order.ErrMessage = dr["errMessage"].ToString();
                            order.InsurPermFee = decimal.Parse(dr["insurPermFee"].ToString());
                            order.ItemNo = dr["itemNo"].ToString();
                            order.OrderNo = dr["OrderNo"].ToString();
                            order.Status = int.Parse(dr["Status"].ToString());
                            result.Orders.Add(order);
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.HasError = true;
                    result.ErrorMessage = ex.Message;
                }
                return result;
            }
    
    
     public class CreateOrderReturnResult
        {
            public bool HasError { get; set; }
            public string ErrorMessage { get; set; }
            public List<CreateOrderReturn> Orders { get; set; }
        }
    
        public class CreateOrderReturn
        {
            public string AdditionalDocument { get; set; }
            public decimal DeliveryCharge { get; set; }
            public string ErrMessage { get; set; }
            public decimal InsurPermFee { get; set; }
            public string ItemNo { get; set; }
            public string OrderNo { get; set; }
            public int Status { get; set; }
        }
  • 相关阅读:
    Markdown基础语法
    Java是什么
    myBatis框架_关于怎么获得多表查询的总记录数
    关于Could not load driverClass ${jdbc.driverClassName}问题解决方案
    java中String与StringBuffer拼接的区别
    部分标签
    基础标签 网页分类
    入坑小开头
    完整版的OpenLDAP搭建全过程
    测试Linux下tcp最大连接数限制
  • 原文地址:https://www.cnblogs.com/xiaoqi742709106/p/4654235.html
Copyright © 2011-2022 走看看