字符串的长度超过上maxJsonLength属性设置的值 [英] The length of the string exceeds the value set on the maxJsonLength property
问题描述
我的WebMethod通过加载通过jQuery的 AJAX
post方法选项卡的内容数据与周围200-300记录。并获得以下错误控制台:
I am loading tab content data through jQuery's ajax
post method via webmethod with around 200-300 records. And getting following error in the console:
错误:Sys.Net.WebServiceFailedException:
Sys.Net.WebServiceFailedException:System.InvalidOperationException--
使用JSON序列化和反串行化过程中的错误
的JavaScriptSerializer。字符串的长度超过设定的值
在maxJsonLength属性。
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.
Chagning的长度
Chagning the length of the
maxJsonLength
于事无补。
Web.config文件设置为以下JSON atributes:
Web.config is set to following JSON atributes:
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644" />
</webServices>
</scripting>
</system.web.extensions>
</configuration>
谁能帮我解决这个问题?
Can anyone help me solve this?
推荐答案
JavaScriptSerialzer有根据名为MaxJsonLength公共财产
JavaScriptSerialzer has a public property named MaxJsonLength according to
<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.configuration.scriptingjsonserializationsection.maxjsonlength.aspx\">http://msdn.microsoft.com/en-us/library/system.web.configuration.scriptingjsonserializationsection.maxjsonlength.aspx
现在,你在哪里你的反序列化JSON,使用
Now, where you are deserializing your json, use this
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<yourObject>(yourJsonString);
这应该很好地工作,我最近通过MSDN想通了这一点,并解决了被窃听我很久的一个问题。
And this should work perfectly, I recently figured this out through msdn and solved a problem that was bugging me for long.
这篇关于字符串的长度超过上maxJsonLength属性设置的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!