. NET using JSON (), Maxjsonlength property Set value problem

Source: Internet
Author: User

"There was an error serializing or deserializing using JSON javascriptserializer. The length of the string exceeds the value set for the Maxjsonlength property "

Business today look for me. The country area on the line shows the number (region ID) instead of the region name.

At that time, I think it is not possible ah, although the control is very old, has been replaced, not to the release date, but the code on the line absolutely no problem ah.

When I go to see the page, just crazy, there is really a problem, but the code on the online master is attached locally to the process is fully OK.

Guess:

1, the online JS file has changed;

2, the configuration file has changed

And then start looking at the Git record discovery today without uploading a record. Look at the online log and find a strange exception: the bold line above.

And then I started to think it was a code problem.

Asked the next Niang, see most of the solutions to this problem:

In the Web. config node, add the following:

<system.web.extensions>    <scripting>        <webServices>            <jsonserialization Maxjsonlength="1024000000" />        </webServices>    </scripting>< /system.web.extensions>

This is used to increase the length value of the maxjsonlength .

Combined with their own projects, the original old control, not the page loading area but take the full amount (the previous development dug pit), usually always use MVC json () to serialize the data into JSON format, yesterday suddenly increased the information of several cities, the amount of data increased to more than 49,000, take the entire data is, the bursting

Maxjsonlength Default value (online is said to be 4M, there is said 2M). Sad reminder of the small, with will not have the QA of the page loaded control also uploaded, fortunately there is no problem.


Problem solved, but the small part still feel that there are doubts, on the query more posts, found a more perfect way:

 Public ActionResult Getlargejsonresult () {  returnnew  contentresult    {         New JavaScriptSerializer {maxjsonlength = Int32.MaxValue}. Serialize (Listresult),        "application/json"    };}

In addition, found a more thorough explanation of the post, attached address: http://www.cnblogs.com/artech/archive/2012/08/15/action-result-03.html

. NET using JSON (), Maxjsonlength property Set value problem

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.