标签:
防止忘记,留着备用
/// <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 "没有数据"; } }
标签:
原文地址:http://www.cnblogs.com/Collision/p/4453519.html