加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 字符串的长度超过maxJsonLength属性上设置的值

发布时间:2020-12-15 08:21:09 所属栏目:百科 来源:网络整理
导读:我有一个.Net Web服务(.asmx),它将一个Json字符串返回给我的客户端.但是,我的一些数据非常大,偶尔会出现此错误. The length of the string exceeds the value set on the maxJsonLength property. 我已将maxJsonLength属性更改为2147483644,但它仍然无效.请
我有一个.Net Web服务(.asmx),它将一个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);
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读