JSON serialized data exceeds maximum value (maxjsonlength)

Source: Internet
Author: User

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.

    1. Jsonobj when the big time will be error
    2. var serializer = new JavaScriptSerializer ();
    3. Return serializer. Serialize (Jsonobj);

Using Newtonsoft.json also has this problem, the solution is to set Maxjsonlength:

    1. var serializer = new JavaScriptSerializer ();
    2. Serializer. Maxjsonlength = Int32.MaxValue; //Set to the maximum value of int
    3. 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:

  1. <system.web.extensions>
  2. <scripting>
  3. <webservices>
  4. <!--units in bytes--
  5. <jsonserializationmaxjsonlength="1024000"/>
  6. </webservices>
  7. </Scripting>
  8. </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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.