zoukankan      html  css  js  c++  java
  • .net 一般處理程序接收集合

    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 () {
              });
  • 相关阅读:
    设计模式
    设计模式
    设计模式
    JS | Reduce
    JS | 数组的深拷贝与浅拷贝
    JS | 数组操作
    Lodash | 指定路径对Object操作
    Git | 场景总结
    ES6 Class
    SpringBoot | Jpa @Id @GeneratedValue
  • 原文地址:https://www.cnblogs.com/zmaiwxl/p/10144003.html
Copyright © 2011-2022 走看看