使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串长度超过
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20141310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds
提问by user3021070
""""""""""""""""""Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":" at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"""""""""""""""""
""""""""""""""""""使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了 maxJsonLength 属性上设置的值。","StackTrace":" 在 System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n 在 System. Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n 在 System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n 在 System .Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext 上下文,
I tried all the answers but still now am getting this error anyone please help.
我尝试了所有答案,但现在仍然遇到此错误,请任何人帮忙。
回答by fejesjoco
阅读:http: //msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.maxjsonlength%28v=vs.110%29.aspx
It says you can specify a length in your configuration file.
它说您可以在配置文件中指定长度。
回答by nyoshi
Be aware that the value of the MaxJsonLength property applies only when you explicitly create an instance of the JavaScriptSerializer class.
请注意,仅当您显式创建 JavaScriptSerializer 类的实例时,MaxJsonLength 属性的值才适用。
回答by Josh
From the MSDN articlelinked by fejescoco, you must specify a maximum length in your configuration.
从fejescoco 链接的MSDN 文章中,您必须在配置中指定最大长度。
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="9001"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
回答by DipakRiswadkar
We had a json object returning from the web service. code was as below
我们有一个从 Web 服务返回的 json 对象。代码如下
JavaScriptSerializer s = new JavaScriptSerializer();
.
.
.
return s.Serialize(bomDataObject);
we had about 5000+ rows causing the above error in serialization.
我们有大约 5000 多行导致上述序列化错误。
visited the following links to get an idea of the maximum json size limits:
访问以下链接以了解最大 json 大小限制:
The maximum length of JSON strings. The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data. We set the code to following to work for our scenario for large data... ofcourse adds load on server and network to load data but it is huge data and we need to displau it !!
JSON 字符串的最大长度。默认为 2097152 个字符,相当于 4 MB 的 Unicode 字符串数据。我们将代码设置为以下以适用于我们的大数据场景......当然会增加服务器和网络的负载以加载数据但它是巨大的数据,我们需要displau它!
JavaScriptSerializer s = new JavaScriptSerializer();
s.MaxJsonLength = int.MaxValue;
.
.
.
.
.
return s.Serialize(bomDataObject);.