ajax json 数据

json_ajax_Datable_IList(T).rar

使用datatable作为后台数据源

例子: 关于JSON的学习/学习json1_datatable.aspx; ToJson.ashx;

 

ASPX页面的js

 

{"Suppliers":[{"SupplierID":"1","CompanyName":"Exotic Liquids","Address":"49 Gilbert St.","City":"London","Country":"UK","Phone":"(171) 555-2222"},{"SupplierID":"2","CompanyName":"New Orleans Cajun Delights","Address":"P.O. Box 78934","City":"New Orleans","Country":"USA","Phone":"(100) 555-4822"},{"SupplierID":"3","CompanyName":"Grandma Kelly's Homestead","Address":"707 Oxford Rd.","City":"Ann Arbor","Country":"USA","Phone":"(313) 555-5735"},{"SupplierID":"4","CompanyName":"Tokyo Traders","Address":"9-8 Sekimai Musashino-shi","City":"Tokyo","Country":"Japan","Phone":"(03) 3555-5011"},{"SupplierID":"5","CompanyName":"Cooperativa de Quesos 'Las Cabras'","Address":"Calle del Rosal 4","City":"Oviedo","Country":"Spain","Phone":"(98) 598 76 54"},
……………………………………

然后用EVAL()把后台传过来的responseText对象转化为js对象

然后用json.Suppliers[index].SupplierID
json.Suppliers[index].CompanyName等访问
比使用Msxml2.DOMDocument控件解析XML方便

 

ToJson.ashx

 

 

使用泛型数组作为后台数据源

关于JSON的学习/使用json_net序列化实体层/Default.aspx; Handler2.ashx;

 

ASPX页面的js

 

{"ID":1,"CompanyName":"Exotic Liquids"},{"ID":2,"CompanyName":"New Orleans Cajun Delights"},{"ID":3,"CompanyName":"Grandma Kelly's Homestead"},{"ID":4,"CompanyName":"Tokyo Traders"},{"ID":5,"CompanyName":"Cooperativa de Quesos 'Las Cabras'"},{"ID":6,"CompanyName":"Mayumi's"},{"ID":7,"CompanyName":"Pavlova, Ltd."},{"ID":8,"CompanyName":"Specialty Biscuits, Ltd."},{"ID":9,"CompanyName":"PB Knäckebröd AB"},{"ID":10,"CompanyName":"Refrescos Americanas LTDA"},{"ID":11,"CompanyName":"Heli Süßwaren GmbH & Co. KG"},

eval转化为js对象,var json
=eval("("+son+")")
json[
0].ID  //output: 1

 Json.NET。它方便我们读取从浏览器流向服务器的JSON对象,也方便在响应流中写入JSON对象。这里下载:Json.NET

 

handle

 

posted @ 2009-01-14 13:52  MyCoolDog  阅读(1148)  评论(0编辑  收藏  举报