asp.net - 我可以在 web.config 中为 maxJsonLength 设置无限长度吗?

标签 asp.net asp.net-mvc json

我正在使用 jQuery 的自动完成功能。当我尝试检索超过 17000 条记录的列表(每条记录的长度不超过 10 个字符)时,它超出了长度并引发错误:

Exception information:
Exception type: InvalidOperationException
Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

我可以在 web.config 中为 maxJsonLength 设置无限长度吗?如果没有,我可以设置的最大长度是多少?

最佳答案

注意:此答案仅适用于 Web 服务,如果您从 Controller 方法返回 JSON,请确保您也阅读了以下 SO 答案:https://stackoverflow.com/a/7207539/1246870


MaxJsonLength property 不能是无限的,是一个整数属性,默认为 102400 (100k)。

您可以在 web.config 中设置 MaxJsonLength 属性:

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 

关于asp.net - 我可以在 web.config 中为 maxJsonLength 设置无限长度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1151987/

相关文章:

c# - 在 Visual Studio 中混淆 .cs 源本身

ASP.Net MVC 3 - 密码保护 View

c# - MVC WebGrid 动态列

c# - 值不能为空 - 应用程序管理器

php - 使用 php 将多个值返回到带有 json 的 jquery.ajax

asp.net - 在应用程序重新启动时清除临时 ASP.NET 文件

c# - 发布 Windows 窗体应用程序 - 图片去哪儿了?

javascript - 通过连接到方法 asp.net MVC 来过滤 Kendo 网格中的数据

javascript - 搜索小写和大写字符

javascript - 如何从 JSON 数组调用函数