zoukankan      html  css  js  c++  java
  • ASP.NET MVC源码分析系列

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

  • 相关阅读:
    文本分类的研究学习
    Python中的TfidfVectorizer参数解析
    Newsgroups数据集介绍
    鸢尾花数据读取的总结
    Knapsack Problems
    3.1.6 Stamps
    3.1.5 Contact
    3.1.4 Shaping Regions
    3.1.3 Humble Numbers
    3.1.2 Score Inflation
  • 原文地址:https://www.cnblogs.com/jinqi79731/p/4694436.html
Copyright © 2011-2022 走看看