Json serialization Newtonsoft.Json version requires more than 7.0

/// <summary>
/// 将DataTable 转换成JSon字符串
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public static string DataTableToJsonWithJavaScriptSerializer(DataTable table)
{
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
List<Dictionary<string, object>> parentRow = new List<Dictionary<string, object>>();
Dictionary<string, object> childRow;
foreach (DataRow row in table.Rows)
{
childRow = new Dictionary<string, object>();
foreach (DataColumn col in table.Columns)
{
childRow.Add(col.ColumnName, row[col].IsDate() ? row[col].ConvertToDataTimeFormat("yyyy-MM-dd") : row[col].ToString());
}
parentRow.Add(childRow);
}
return jsSerializer.Serialize(parentRow);
}

Guess you like

Origin www.cnblogs.com/roper/p/11804314.html
Recommended