码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET MVC源码分析系列

时间:2015-08-01 18:52:08      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

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进行的序列化

 

ASP.NET MVC源码分析系列

标签:

原文地址:http://www.cnblogs.com/jinqi79731/p/4694436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!