日期:2014-05-17 浏览次数:20436 次
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
}
}
});