将jquery json传递到asp.net httphandler

将jquery json传递到asp.net httphandler,第1张

将jquery json传递到asp.net httphandler

尝试

data: JSON.stringify([{id: "10000", name: "bill"},{id: "10005", name: "paul"}])

编辑从属性名称中删除了引号

另外,JSON字符串需要以其他方式读取

string jsonString = String.Empty;HttpContext.Current.Request.InputStream.Position = 0;using (StreamReader inputStream = new StreamReader(HttpContext.Current.Request.InputStream)){     jsonString = inputStream.ReadToEnd();}

一个可行的解决方案

public void ProcessRequest(HttpContext context){    var jsonSerializer = new JavascriptSerializer();    var jsonString = String.Empty;    context.Request.InputStream.Position = 0;    using (var inputStream = new StreamReader(context.Request.InputStream))    {        jsonString = inputStream.ReadToEnd();    }    var emplList = jsonSerializer.Deserialize<List<Employee>>(jsonString);    var resp = String.Empty;    foreach (var emp in emplList)    {        resp += emp.name + " \ ";    }    context.Response.ContentType = "application/json";    context.Response.ContentEncoding = Encoding.UTF8;    context.Response.Write(jsonSerializer.Serialize(resp));}public class Employee{    public string id { get; set; }    public string name { get; set; }}public bool IsReusable{    get    {        return false;    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5622786.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存