將#region數據表轉換為Json字符串實例的方法
///& lt;總結& gt
/// GetClassTypeJosn的摘要描述
///& lt;/summary & gt;
公共類GetClassTypeJosn : IHttpHandler
{
///& lt;總結& gt
///文件名:DataTable和Json字符串轉換。
///版權所有(三)創造家族財富梁
///創建徽標:2013-08-03
///& lt;/summary & gt;
//指令示例
公共void ProcessRequest(HttpContext上下文)
{
語境。response . content type = " application/JSON ";
語境。response . Charset = " utf-8 ";
HttpRequest req =上下文。請求;
string method = req["method"]。ToStr()。to lower();
//獲取合同明細表數據表,轉換成Json字符串。
if (method == "txtdate ")
{
字符串json =
博。MakeContractMx bll = new MakeContractMx();
數據集ds = bll。get datatable();
如果(ds。Tables . Count & gt0)
{
json =ToJson(ds。表[0]);
}
語境。response . Write(JSON);
返回;
}
}
公共布爾值是可重用的
{
得到
{
返回false
}
}
}
#結束區域
將#region Json字符串轉換為DataTable實例的方法
公共數據表
{
DataTable dt = ToDataTable(JSON);
返回dt;
}
#結束區域
#區域數據表轉換為Json字符串
///& lt;總結& gt
/// DataTable對象被轉換為Json字符串。
///& lt;/summary & gt;
///& lt;param name = " dt " & gt& lt/param & gt;
///& lt;returns & gt& lt/returns & gt;
公共靜態字符串ToJson(此數據表dt)
{
JavaScript serializer JavaScript serializer = new JavaScript serializer();
JavaScript序列化程序。MaxJsonLength = Int32。MaxValue//獲取最大值
ArrayList ArrayList = new ArrayList();
foreach(DataRow dt中的DataRow。行)
{
字典& lt字符串,對象& gtdictionary =新詞典& lt字符串,對象& gt();//實例化壹個參數集
foreach(DataColumn dt中的DataColumn。列)
{
字典。添加(dataColumn。ColumnName,dataRow[dataColumn。列名]。ToStr());
}
數組列表。添加(字典);//將鍵值添加到//ArrayList集合
}