您的位置:首页 > 编程语言 > ASP

ASP.NET MVC源码分析系列

2015-08-01 17:59 676 查看
Controller下的JsonResult的ExecuteResult方法

public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if ((this.JsonRequestBehavior == JsonRequestBehavior.DenyGet) && string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(MvcResources.JsonRequest_GetNotAllowed);
}
HttpResponseBase response = context.HttpContext.Response;
if (!string.IsNullOrEmpty(this.ContentType))
{
response.ContentType = this.ContentType;
}
else
{
response.ContentType = "application/json";
}
if (this.ContentEncoding != null)
{
response.ContentEncoding = this.ContentEncoding;
}
if (this.Data != null)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
if (this.MaxJsonLength.HasValue)
{
serializer.MaxJsonLength = this.MaxJsonLength.Value;
}
if (this.RecursionLimit.HasValue)
{
serializer.RecursionLimit = this.RecursionLimit.Value;
}
response.Write(serializer.Serialize(this.Data));
}
}


此处使用的JavaScriptSerializer进行的序列化
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: