views:

188

answers:

2

I'm hoping to get some clarification on the maxJsonLength property. Here is some background information.

I was having an issue with an AJAX response not being returned in a .NET web application using jQuery. When the user changed a drop down list, I manually built and displayed some HTML. The issue was that one specific selection returned a string that was about 140kB but it would not display in the browser. I narrowed the problem down to the length of the string being too long. In searching SO and elsewhere, I found that the issue could be resolved by manually setting the value of maxJsonLength in my web.config.

My confusion is about the default value of th maxJsonLength property. Some answers say it's 2097152 characters and reference this MSDN link. But others have said the default length is 102400 and reference this other MSDN link. In my testing, I've come to the conclusion that the default is 102400 bytes but I'm not sure of the reason for the other default value.

+1  A: 

Creating a page on a website with the following in the code behind:

JavaScriptSerializer serializer = new JavaScriptSerializer();

Response.Write("Max Length: " + serializer.MaxJsonLength);

Led to an output of:

Max Length: 2097152

So I would go with the value defined in the docs rather than the How to.

Note however that this is Characters, and not bytes explicitly:

The default is 2097152 characters, which is equivalent to 4 MB of Unicode string data

Zhaph - Ben Duguid
So it appears that if you programmatically create the serializer then it uses the default of 2097152, but if you are just retrieving JSON data through an AXAX request, the default is 102400 bytes. Thanks for the input but I'm still unclear as to why there's the discrepancy.
Jonathan S.
A: 

I ran into similar issues returning JSON from a web service. I set the maxJsonLength in web.config to a value large enough to handle the data I was sending back.

Tim