ASP.Net WebForm applications using 一般处理程序 .ashxAjax to the data Jsonwhen the type of display in the foreground
Since the DataTabletype can not be directly converted into a Jsonformat, by the DataTabletype first converted into a List<T>set, then the List<T>set is converted into Jsonthe format
Conversion process
The DataTableconversion type into List<T>the collection
publicstatic List<Student>GetStuInfo(){
string sql =@"select ID,Name from StudentInfo";DataTable dt = Helper.DBHelper.GetDataTable(sql,null);//实例化一个 Student 的 List<T>集合
List<Student> list =newList<Student>();foreach(DataRow item in dt.Rows){
// 实例化一个 Student 类的对象Student info =newStudent{
ID = Convert.ToInt32(item["ID"]),
Name = item["Name"].ToString(),};
list.Add(info);}return list;}
The List<T>aggregate data set into a sequence Jsonformat