ASP. NET MVC 4 JSON Big Data exception hint JSON character length exceeds limit exception

Source: Internet
Author: User

Today, the customer suddenly came to me to say that in the background to add an extra long article, all the background of the article is not displayed. The front-end display is Easyui, and the returned data is all in JSON. Following the same operation according to the customer's description, an error occurred during the firebug of the Ajax returned exception "serialization or JSON JavaScriptSerializer. The length of the string exceeds the value set on the Maxjsonlength property "

This exception is thrown when executing the jsonresult in MVC, and according to the message of the exception, the serialized string exceeds the maxjsonlength limit. and learned that this attribute is provided by JavaScriptSerializer, because the MVC built-in Jsonresult is serialized with JavaScriptSerializer. A quick search on the Internet, encountered many of this problem, most of the recommended solution is to add the following configuration in Web. config, set the length of the Maxjsonlength

1 <system.web.extensions>2        <Scripting>3            <webservices>4                <jsonserializationMaxjsonlength= "102400"/>5            </webservices>6        </Scripting>7 </system.web.extensions>

Then change the size of the maxjsonlength as needed

Works fine, but the problem remains, and no matter how much maxjsonlength is set to be invalid

No way, can only continue to search for information.

Originally the MVC framework built-in Jsonresult code, when using JavaScriptSerializer, are the default values, not read from the Maxjsonlength value, that is, ignore this configuration.

Finally found the answer on the StackOverflow.

Add two Jsonresult to the controller and then use return Largejson () instead of return JSON () in the action call that needs to return the Big Data JSON ()

 PublicJsonresult Largejson (Objectdata) {     return NewSystem.Web.Mvc.JsonResult () {Data=data, Maxjsonlength=Int32.MaxValue,};} PublicJsonresult Largejson (Objectdata,jsonrequestbehavior behavior) {            return NewSystem.Web.Mvc.JsonResult () {Data=data, Jsonrequestbehavior=behavior, Maxjsonlength=Int32.MaxValue};}

Specific website: http://stackoverflow.com/questions/4155014/json-asp-net-mvc-maxjsonlength-exception

Said here have to sigh

A lot of technical problems, Baidu came out of the results are no other foreign cattle, later encountered technical problems or Google point

ASP. NET MVC 4 JSON Big Data exception hint JSON character length exceeds limit exception

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.