zoukankan      html  css  js  c++  java
  • c# DataTable 序列化json

     if (ds.Tables[0].Rows.Count != 0)
                    {
                        var list = GetJsonString(ds.Tables[0]);
                        jsonStr = "{'jsonStr':'" + list + "','result':'1'}";  
                    }

     public string GetJsonString(DataTable DS)
        {
          List<Voucher> list = new List<Voucher>();
     
           
            for (int i = 0; i < DS.Rows.Count; i++)
            {
                Voucher cd=new Voucher();
                cd.id=DS.Rows[i]["VID"].ToString();
                list.Add(cd);
            }
            VoucherList voucherlist = new VoucherList();
            voucherlist.GetVoucher = list;
     
            return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(voucherlist);
     
        }
        public class Voucher
        {
            public string id{ get; set; }
            
        }
        public class VoucherList
        {
            public System.Collections.Generic.List<Voucher> GetVoucher { get; set; }
        }
  • 相关阅读:
    Eighth scrum meeting
    Seventh scrum meeting
    Sixth scrum meeting
    Fifth scrum meeting
    Forth scrum meeting
    Third scrum meeting
    2019-07-25 L430 生物 GPS
    L429 Why Do Smart People Do Foolish Things?
    L427 长难句
    L426
  • 原文地址:https://www.cnblogs.com/ft-Pavilion/p/5653797.html
Copyright © 2011-2022 走看看