//只能写个类来转啦....#region DataTable 转换为Json字符串实例方法/// <summary>/// GetClassTypeJosn 的摘要说明/// </summary>public class GetClassTypeJosn : IHttpHandler{/// <summary>/// 文件名:DataTable 和Json 字符串互转/// 版权所有:Copyright (C) Create Family Wealth liangjw/// 创建标示:2013-08-03/// </summary>//用法说明实例public void ProcessRequest(HttpContext context){context.Response.ContentType = "application/json";context.Response.Charset = "utf-8";HttpRequest req = context.Request;string method = req["method"].ToStr().ToLower();//获取合同明细列表 DataTable 转换为Json字符串if (method == "txtdate"){string json = "";BO.MakeContractMx bll = new MakeContractMx();DataSet ds = bll.GetDataTable();if (ds.Tables.Count > 0){json =ToJson(ds.Tables[0]);}context.Response.Write(json);return;}}public bool IsReusable{get{return false;}}}#endregion#region Json字符串转换为DataTable 实例方法public DataTable JsonToDataTable(json){DataTable dt= ToDataTable(json);return dt;}#endregion#region DataTable 转换为Json 字符串/// <summary>/// DataTable 对象 转换为Json 字符串/// </summary>/// <param name="dt"></param>/// <returns></returns>public static string ToJson(this DataTable dt){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].ToStr());}arrayList.Add(dictionary); //ArrayList集合中添加键值}