C#中DataTable转换JSON

#region 将DataTable转换为json
public string dt2json(DataTable dt)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
System.Collections.ArrayList dic = new System.Collections.ArrayList();
foreach (DataRow dr in dt.Rows)
{
System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
foreach (DataColumn dc in dt.Columns)
{
drow.Add(dc.ColumnName, dr[dc.ColumnName]);
}
dic.Add(drow);

}
//序列化
return jss.Serialize(dic);
}
#endregion

结伴旅游网www.jieberu.com

推推族www.tuituizu.com

C#中DataTable转换JSON

上一篇:zabbix4.4监控mysql主从复制


下一篇:QT QNetworkAccessManager请求响应为空