码迷,mamicode.com
首页 > Web开发 > 详细

DataSet转Json 方法

时间:2015-04-24 15:57:07      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:

防止忘记,留着备用   



/// <summary> /// DATASET转JSON /// </summary> /// <param name="ds"></param> /// <returns></returns> public static string ToJson(DataSet ds) { try { string json = "["; foreach (DataRow i in ds.Tables[0].Rows) { json += "{"; foreach (DataColumn column in ds.Tables[0].Columns) { json += "" + column.ColumnName + "‘:"; //json += "‘" + column.ColumnName + "‘:‘" + i[column.ColumnName].ToString() + "‘,"; if (column.DataType == typeof(DateTime) || column.DataType == typeof(string)) { json += "" + i[column.ColumnName].ToString() + "‘,"; } else { json += "" + i[column.ColumnName].ToString() + ","; } } json = json.Substring(0, json.LastIndexOf(",")) + "},"; } json = json.Substring(0, json.LastIndexOf(",")); return json + "]"; } catch { return "没有数据"; } }

 

DataSet转Json 方法

标签:

原文地址:http://www.cnblogs.com/Collision/p/4453519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!