Skip to content Skip to sidebar Skip to footer

Javascriptserializer.maxjsonlength Exceeded. What's The Best Practice For Handling This?

I've got a large amound of data I'm sending down to the client using jQuery's $.ajax() function. I'm calling a method in a ASP.NET web service that returns the JSON data. Everythin

Solution 1:

The only way to set the maximum length for web methods that are called from client script is through the web.config file (below). What is your issue with setting this? I would do this every time over multiple xhr calls to stream parts of the data.

<system.web.extensions><scripting><webServices><jsonSerializationmaxJsonLength="500000"></jsonSerialization></webServices></scripting></system.web.extensions>

UPDATE: The default size is 2097152 which is equivalent to 4 MB of Unicode string data. Are you really going to send that much data back to the client? If so ouch and you prob need to look at the app design as the user experience will be slow and cumbersome.

Solution 2:

2147483647 is the correct value to use. Just to avoid confusion in the code you can use something like

var JsonSerializer = new JavaScriptSerializer();
JsonSerializer.MaxJsonLength = Int32.MaxValue;

Solution 3:

The maximum value for this property is 2147483647 according to this forum post.

I've not spent any time optimizing the data I return, yet (I'll do that before anyone sees it) - but with this value set, IE has started giving me the 'a script on the page is taking too long do you want to kill it' message.

A solution would be to chunk the data - does anyone know of a nice way to do this (in jQuery ideally)? I could just do another ajax call in the success handler, of course.

Solution 4:

The maximum allowed length is the maximum value an Integer can hold which happens to be - 2147483647

Solution 5:

add this snippet to web.config :

<system.web.extensions><scripting><webServices><jsonSerializationmaxJsonLength="2147483647"/></webServices></scripting>

and in your c# code:

JavaScriptSerializerjss=newJavaScriptSerializer();
 jss.MaxJsonLength = Int32.MaxValue;
 ...
 ...

Post a Comment for "Javascriptserializer.maxjsonlength Exceeded. What's The Best Practice For Handling This?"