/// 将datatable转换为json 3 /// </summary> 4 /// <param name="dtb">Dt</param> 5 /// <returns>JSON字符串</returns> 6 public static string Dtb2Json(DataTable dtb) 7 { 8 JavaScriptSerializer jss = new JavaScriptSerializer(); 9 System.Collections.ArrayList dic = new System.Collections.ArrayList(); 10 foreach (DataRow dr in dtb.Rows) 11 { 12 System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>(); 13 foreach (DataColumn dc in dtb.Columns) 14 { 15 drow.Add(dc.ColumnName, dr[dc.ColumnName]); 16 } 17 dic.Add(drow); 18 19 } 20 //序列化 21 return jss.Serialize(dic); 22 }
将datatable转换为json
最新推荐文章于 2024-05-25 07:12:35 发布