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

DataTable转换JSON

时间:2015-06-08 14:59:45      阅读:117      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!