关于getjson 的知识 http://www.jb51.net/article/26517.htm###
在·Ashx文件中
代码如下:
if(context.Request["iUnid"]==null)
return;
context.Response.ContentType = "text/plain";
Customer customer = new Customer
{ Unid = 1, CustomerName = "宋江", Memo = "天魁星", Other = "黑三郎" };
Customer customer2 = new Customer
{ Unid = 2, CustomerName = "吴用", Memo = "天机星", Other = "智多星" };
List<Customer> _list = new List<Customer>();
_list .Add(customer);
_list .Add(customer2);
int iCustomerId =Convert.ToInt32(context.Request["iUnid"]);
var cus = from q in _list
where q.Unid == iCustomerId
select q;
string strJson = Newtonsoft.Json.JsonConvert.SerializeObject (cus);
context.Response.Write(strJson);
代码如下:
function GetCustomer_AshxWithPara() {
$.getJSON(
"webdata/Json_2.ashx", //需要去 webdata/Json_2.ashx中取数据
{ iUnid: 1 }, //这是需要传到 webdata/Json_2.ashx中的值,从而筛选数据
function(data) {
var tt = "";
$.each(data, function(k, v) {
$.each(v, function(kk, vv) {
tt += kk + ":" + vv + "<br/>";
});
});
$("#divmessage").html(tt);
});
}
序列化json也可以用:
*.ashx中,格式化对象成JSON:
引用:using Newtonsoft.Json
JsonConvert.SerializeObject(object);