首页 > Web开发 > 详细

DataTable转换JSON

时间:2015-06-08 14:57:20      阅读:238      评论:0      收藏:0      [点我收藏+]

public static string getJson2(this DataTable dt)
{
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
foreach (DataRow dr in dt.Rows)
{
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (DataColumn dc in dt.Columns)
{
result.Add(dc.ColumnName, dr[dc]);
}
list.Add(result);
}
string resultString = list.ToJson();
string json = @"{""rows"":" + resultString + @",""total"":""" + list.Count + @"""}";
return json;
}

DataTable转换JSON

原文:http://www.cnblogs.com/siyechenmu/p/4560832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!