ASP技術,ASP.NET MVC源碼分析系列

 2023-11-07 阅读 23 评论 0

摘要:Controller下的JsonResult的ExecuteResult方法 public override void ExecuteResult(ControllerContext context) {if (context == null){throw new ArgumentNullException("context");}if ((this.JsonRequestBehavior == JsonRequestBehavior.DenyGe

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

?

轉載于:https://www.cnblogs.com/jinqi79731/p/4694436.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/167835.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息