1. Serialization:
The following code will error when the object is too large: There was an error serializing or deserializing. The length of the string exceeds the value set for the Maxjsonlength property.
- Jsonobj when the big time will be error
- var serializer = new JavaScriptSerializer ();
- Return serializer. Serialize (Jsonobj);
Using Newtonsoft.json also has this problem, the solution is to set Maxjsonlength:
- var serializer = new JavaScriptSerializer ();
- Serializer. Maxjsonlength = Int32.MaxValue; //Set to the maximum value of int
- Return serializer. Serialize (Jsonobj);
2. Ajax Access WebService:
With jquery access to WebService, if the post data is too large, you will also receive a HTTP500 error, and the workaround is to set the maxjsonlength in Web. config:
- <system.web.extensions>
- <scripting>
- <webservices>
- <!--units in bytes--
- <jsonserializationmaxjsonlength="1024000"/>
- </webservices>
- </Scripting>
- </system.web.extensions>
Access Call method
JavaScriptSerializer serializer = new JavaScriptSerializer ();
32
Scriptingjsonserializationsection section = configurationmanager.getsection ("System.web.extensions/scri Pting/webservices/jsonserialization ") as scriptingjsonserializationsection;
34
if (section! = null)
36 {
Panax Notoginseng Serializer. maxjsonlength = section. Maxjsonlength;
Serializer. Recursionlimit = section. Recursionlimit;
39}
JSON serialized data exceeds maximum value (maxjsonlength)