我正在尝试在 mvc 操作方法中发布大 json。导致错误
使用 JSON 进行序列化或反序列化期间出错 JavaScriptSerializer。字符串的长度超过设置的值 在 maxJsonLength 属性上。参数名称:输入
我知道SO和google上有很多帖子,我已经尝试了很多解决方案,但没有一个对我有用:
我尝试过:更新的网页配置
在 system.web 中更新了此语句
<httpRuntime targetFramework="4.5.1" maxRequestLength="1073741824" />
和以下行在 Systerm.webserver
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
添加上述行后,它在本地为我工作,但在服务器上更新相同的值后,它不起作用,它抛出上述错误。
更新
IIS Version 7.5
尝试将以下内容添加到您的 web.config
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="{required length of json in bytes}" />
</webServices>
</scripting>
</system.web.extensions>
</configuration>
最大值为 2147483647,默认值为 102400 (100kb(,这可能是您的问题。
您是否尝试过以下方法:
-
将数据作为对象发送,不像 ajax 调用中的
url
参数,如下所示。$.ajax({ type: "POST", url: url, contentType: "application/json; charset=utf-8", data: JSON.stringify(data), dataType: "json", success: function (data) { }, error: function (a, b, c) { console.log(a); } });
-
你可以看到我的帖子。