MVC DataTable转ArrayList转JSON返回JSON到页面

if (dt != null)
{
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
ArrayList arrayList = new ArrayList();
foreach (DataRow dataRow in dt.Rows)
{
Dictionary<string, object> dictionary = new Dictionary<string, object>(); //实例化一个参数集合
foreach (DataColumn dataColumn in dt.Columns)
{
dictionary.Add(dataColumn.ColumnName, dataRow[dataColumn.ColumnName].ToString());
}
arrayList.Add(dictionary); //ArrayList集合中添加键值
}
return Json(arrayList, JsonRequestBehavior.AllowGet); //返回一个json字符串

}

原文地址:https://www.cnblogs.com/914556495wxkj/p/6767020.html