字符串的长度超过了 maxJsonLength 属性 上设置的值

length of the string exceeds the value set on the maxJsonLength property

我有一个 .Net Web 服务 (.asmx),它将 return 一个 Json 字符串发送给我的客户端。但是,我的某些数据非常大,偶尔会出现此错误。

The length of the string exceeds the value set on the maxJsonLength property.

我已经将 maxJsonLength 属性 更改为 2147483644,但它仍然不起作用。请帮忙...谢谢。

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



[WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public void GetData(string login)
        {
            // throw an error on this line...
            string result = new JavaScriptSerializer().Serialize(service.GetData(login));


            Context.Response.Write(result);
        }

感谢 Ed Gibbs 和@NextInLine 的建议。我做了如下修复,现在效果很好。我还从 web.config

中删除了 "system.web.extensions" 部分
[WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public void GetData(string login)
        {

            // when the amount of data return is huge
            var serializer = new JavaScriptSerializer();

            // we need to do this.
            serializer.MaxJsonLength = Int32.MaxValue;


            var result = serializer.Serialize(service.GetData(login));


            Context.Response.Write(result);
        }