/// <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);
}