我通过jQuery的ajax post方法通过webmethod加载选项卡内容数据,大约有200-300条记录。并在控制台中获取以下错误:
Error: Sys.Net.WebServiceFailedException:
Sys.Net.WebServiceFailedException: System.InvalidOperationException–
Error during serialization or deserialization using the JSON
JavaScriptSerializer. The length of the string exceeds the value set
on the maxJsonLength property.
缩短长度
maxJsonLength
没有帮助
Web.config设置为跟随JSON属性:
<configuration> <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="2147483644" /> </webServices> </scripting> </system.web.extensions> </configuration>
任何人都可以帮我解决这个问题吗?
解决方法
根据JavaScriptSerialzer有一个名为MaxJsonLength的公共属性
现在,你正在反序列化你的json,使用这个
JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; //Or any size you want to use,basically int maxValue is 2GB,you shouldn't need this big json string to deserialize,else you are doing it wrong. myObject obj = serializer.Deserialize<myObject>(yourJsonString);
这应该是完美的,我最近通过msdn弄清楚了这一点,并解决了一个很长的问题。