页面JQ提交代码:
- function test() {
- var dd = [{ 'code': '111111',
- 'des': '种鸡',
- "batch": [
- { "code": "123", "count": "4" },
- { "code": "134", "count": "53" }
- ]
- },
- { 'code': '222222',
- 'des': '种蛋',
- "batch": [
- { "code": "888", "count": "8" },
- { "code": "999", "count": "0" }
- ]
- }
- ];
- $.post("AjaxHandler.ashx",JSON.stringify(dd), function (theback) {
- alert(theback);
- },"json");
- }
AjaxHandler.ashx解析数据的代码:
- public class Dan
- {
- [ScriptIgnore]
- public string code{get;set;}
- public string des { get; set; }
- public Batch[] batch { get; set; }
- }
- public class Batch
- {
- [ScriptIgnore]
- public string code { get; set; }
- public int count { get; set; }
- }
- /// <summary>
- /// AjaxHandler 的摘要说明
- /// 原文播客:http://blog.youkuaiyun.com/bluceyoung
- /// </summary>
- public class AjaxHandler : IHttpHandler
- {
- JavaScriptSerializer jsc = new JavaScriptSerializer();
- public void ProcessRequest(HttpContext context)
- {
- Dan[] d;
- d= jsc.Deserialize<Dan[]>(context.Request.Params[0].ToString());
- context.Response.ContentType = "text/plain";
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }