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

datatable转json

时间:2015-06-24 16:17:03      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

//将datatable转化为json
public string DataTableToJSON(DataTable dt)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
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].ToString());
}
list.Add(result);
}
return jss.Serialize(list);
}

datatable转json

标签:

原文地址:http://www.cnblogs.com/whwfwfy/p/4597775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!