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
There are two defaults for MaxJsonLength depending on how JavaScriptSerializer is created.
It is 2097152 when serializer is created directly. Relevant code is:
public class JavaScriptSerializer {
...
internal const int DefaultMaxJsonLength = 2097152;
...
public JavaScriptSerializer(...) {
...
MaxJsonLength = DefaultMaxJsonLength;
}
}
It is 102400 when serializer is created by ASP.NET MVC (or older). Relevant code is:
public sealed class ScriptingJsonSerializationSection : ConfigurationSection {
...
private static readonly ConfigurationProperty _propMaxJsonLength =
new ConfigurationProperty("maxJsonLength",
typeof(int),
102400,
...);
...
[ConfigurationProperty("maxJsonLength", DefaultValue = 102400)]
public int MaxJsonLength { ... }
...
}
There are several places which assign serializer.MaxJsonLength to this value — all of them are in ASP.NET-related code.
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
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.