字符串的长度超过在maxJsonLength属性上设置的值 [英] length of the string exceeds the value set on the maxJsonLength property

查看:135
本文介绍了字符串的长度超过在maxJsonLength属性上设置的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.Net Web服务(.asmx),它将向我的客户端返回一个Json字符串.但是,我的某些数据确实很大,偶尔会出现此错误.

I have a .Net Web service (.asmx) which will return a Json string to my client. However, some of my data is really large and I get this error occasionally.

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

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

我已将maxJsonLength属性更改为2147483644,但仍然无法正常工作.请帮忙...谢谢.

I've changed the maxJsonLength property to 2147483644, but it still doesn't work. Please help... Thank you.

 <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"部分

Thanks to Ed Gibbs and @NextInLine 's suggestion. I did the fix as below and it work like a charm now. I also removed the "system.web.extensions" portion away from my web.config

[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);
        }

这篇关于字符串的长度超过在maxJsonLength属性上设置的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆