传递给后台的Json数据解析
后台代码如下:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; HttpRequest request = context.Request; if (request.InputStream != null && request.InputStream.Length > 0) { StreamReader reader = new StreamReader(request.InputStream); string json = reader.ReadToEnd(); //接下来就是使用Newtonsoft.Json解析json字符串 //JsonConvert.DeserializeObject<CommonTableParam>(json);
//然后就可以使用前台传给后台的Json数据了 } }
前端代码如下: function extendAjaxParam(newSrc) { var src = { type: "post", dataType: "json", contentType: "application/json;charset=utf-8", error: function(err) { alert(err.responseText); } } return $.extend({}, src, newSrc); } $.ajax(extendAjaxParam({ url: 自定义的url, // data: JSON.stringify({ "id": id, "name": name }), success: function(data) { } }));