码迷,mamicode.com
首页 > Web开发 > 详细

.net 一般處理程序接收集合

时间:2018-12-19 16:59:47      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:type   int   process   als   stream   集合   java   serialize   response   

1.後端代碼

 public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "application/json";
            context.Response.ContentEncoding = Encoding.UTF8;

            Stream inputStream = context.Request.InputStream;
            Encoding encoding = context.Request.ContentEncoding;
            StreamReader streamReader = new StreamReader(inputStream, encoding);

            string strJson = streamReader.ReadToEnd();
            JavaScriptSerializer json = new JavaScriptSerializer();
            var test = json.Deserialize<List<TestClass>>(strJson);
            context.Response.ContentType = "text/plain";
            
            context.Response.Write("Hello World");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    public class TestClass
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }

 

2.前端代碼

         var array2= [{ name:"a", age: 1 }, { name:"b", age: 2 }, { name:"c", age: 3}]
         var data = JSON.stringify(array2);
         $.post("Handler1.ashx", data, function () {
          });

 

.net 一般處理程序接收集合

标签:type   int   process   als   stream   集合   java   serialize   response   

原文地址:https://www.cnblogs.com/zmaiwxl/p/10144003.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!