【问题标题】:Posting large JSON to MVC action method : The length of the string exceeds the value将大 JSON 发布到 MVC 操作方法:字符串的长度超过了值
【发布时间】:2017-03-19 20:17:39
【问题描述】:

我正在尝试在 mvc 操作方法中发布大 json。 导致错误

使用 JSON 进行序列化或反序列化时出错 JavaScript 序列化器。字符串长度超过设置的值 在 maxJsonLength 属性上。参数名称:输入

我知道 SO 和 google 上有很多帖子,我尝试了很多解决方案,但没有一个对我有用:

我尝试过的: 更新了 Web.Config

system.web

中更新了此声明
<httpRuntime targetFramework="4.5.1" maxRequestLength="1073741824"  />

以及 Systerm.webserver 中的以下行

<security>
      <requestFiltering>
                <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>

添加以上行后,它在本地对我有用,但在服务器上更新相同的值后它不起作用,它会抛出上述错误。

更新

IIS Version 7.5

【问题讨论】:

  • 您的服务器运行的是哪个版本的 iis?
  • @DaiBok IIS 7.5 版

标签: json asp.net-mvc


【解决方案1】:

尝试将以下内容添加到您的 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),这可能是您的问题。

【讨论】:

    【解决方案2】:

    您是否尝试过以下方法:

    1. 在 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); }
                  });
      
    2. 你可以看到我的POST

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 2012-09-24
      相关资源
      最近更新 更多