标签:atime tostring str ali ons 字符 stat 字符串 需要
/// <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);
}
Json序列化Newtonsoft.Json版本需要7.0以上
标签:atime tostring str ali ons 字符 stat 字符串 需要
原文地址:https://www.cnblogs.com/roper/p/11804314.html