using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
/// <summary>
/// 将DataTable类型转为JSON类型供使用
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public string DataTableToJson(DataTable dt)
{
string result = "";
result = JsonConvert.SerializeObject(dt, new DataTableConverter());
return result;
}
/// <summary>
/// 将JSON类型转为DataTable类型供使用
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public DataTable JsonToDataTable(string json)
{
DataTable dt = JsonConvert.DeserializeObject<DataTable>(json);
return dt;
}