标签:get ble pre color span index turn foreach public
1 /// <summary> 2 /// 获取json串,根据datatable 3 /// </summary> 4 /// <param name="dt"></param> 5 /// <returns></returns> 6 public static String GetJsonByTable(DataTable dt) 7 { 8 String rtn = String.Empty; 9 String data = String.Empty; 10 11 rtn += "["; 12 foreach (DataRow dr in dt.Rows) 13 { 14 data = "{"; 15 foreach (DataColumn dc in dt.Columns) 16 { 17 if (dt.Columns.IndexOf(dc) != dt.Columns.Count - 1) 18 { 19 data += "\"" + dc.ColumnName + "\":\"" + dr[dc].ToString() + "\","; 20 } 21 else 22 { 23 data += "\"" + dc.ColumnName + "\":\"" + dr[dc].ToString() + "\""; 24 } 25 } 26 if (dt.Rows.IndexOf(dr) != dt.Rows.Count - 1) 27 { 28 data += "},"; 29 } 30 else 31 { 32 data += "}"; 33 } 34 rtn += data; 35 } 36 37 rtn += "]"; 38 39 return rtn; 40 }
标签:get ble pre color span index turn foreach public
原文地址:http://www.cnblogs.com/loge/p/7500073.html