DataSet转Json 方法
防止忘记,留着备用
/// <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 "没有数据"; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。