标签:
方法:
public static string GetJsonByDataset(DataSet ds)
{
if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
{
return null;
}
StringBuilder sb = new StringBuilder();
foreach (DataTable dt in ds.Tables)
{
sb.Append(string.Format("["));
foreach (DataRow dr in dt.Rows)
{
sb.Append("{");
for (int i = 0; i < dr.Table.Columns.Count; i++)
{
sb.AppendFormat("\"{0}\":\"{1}\",", dr.Table.Columns[i].ColumnName, dr[i].ToString());
}
sb.Remove(sb.ToString().LastIndexOf(‘,‘), 1);
sb.Append("},");
}
sb.Remove(sb.ToString().LastIndexOf(‘,‘), 1);
sb.Append("]");
}
return sb.ToString();
}
asp.net 根据dataset获取大字符串(直接转出json)
标签:
原文地址:http://www.cnblogs.com/jobyym/p/4816978.html