日期:2014-05-17 浏览次数:20493 次
List<Person> pList = new List<Person>(); Person p = null; foreach(DataRow row in DataTable1.Rows){ p = new Person(); p.ID = Convert.ToInt32(row["ID"]); p.Name = row["Name"].ToString(); pList.Add(p); } JavaScriptSerializer jss = new JavaScriptSerializer(); string jsonArr = jss.Serialize(pList); context.Response.Write(jsonArr); public class Person{ public int ID{get;set;} public string Name{get;set;} }
------解决方案--------------------
$.ajax({ url: "../Handler/TestHandler.ashx", async: true, success: function (data, status) { if (status == "success") { var json = $.parseJSON(data); //遍历json } } });