向服务器发送josn字符串,服务器端解析
<script type="text/javascript"> $(function () { $("#btnsave").click(function () { var json = { "age": 12, "address": "hk", "ship": [ { "custID": "sz", "cpname": "bookstrf" },{ "custID": "fkff", "cpname": "kfg"}] }; $.ajax({ type: "post", url: "Handler/test.ashx", datatype: "json", data: { name: JSON.stringify(json) }, async: true, success: function (data) { alert(data); } }); }); }); </script>
public class test : IHttpHandler { public void ProcessRequest(HttpContext context) { string ss = context.Request["name"]; var serialize = new JavaScriptSerializer(); var t = serialize.Deserialize<Model>(ss); } public bool IsReusable { get { return false; } } class Model { public int age {get; set;} public string address{get; set;} public List<Ship> ship{get; set;} } class Ship { public string custID{get; set;} public string cpname { get; set; } } }
//得到数据对象: