我正在使用 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/