传递给后台的Json数据解析


后台代码如下:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
HttpRequest request = context.Request;
if (request.InputStream != null && request.InputStream.Length > )
{
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) { }
}));
上一篇:常用MarkDown标记


下一篇:ajax请求传过来的json数据直接转成对应的实体类时出错:400 Bad Request 不进入controller