//1st way
public string GetSomeData()
{
List<SomeObject> largeCollection = GetLargeDataCollection();
JavaScriptSerializer serializer = new JavaScriptSerializer();
json = serializer.Serialize(largeCollection); // FAILS - MaxJsonLength exceeded OK
return json;
}
//2nd way
public string GetData()
{
List<Data> resData = GetLargeDataCollection();
// Pre-serialize with Newtonsoft (creates ~10MB JSON string)
json = JsonConvert.SerializeObject(resData);
return json;
}
[HttpGet]
public JsonResult GetUsers()
{
var Data = GetData(); // 10MB string
// This works fine even though MVC's Json() has ~100KB limit
return Json(new {
data = Data, // 10MB pre-serialized JSON string
}, JsonRequestBehavior.AllowGet);
}
When JavaScriptSerializer serializes { data: "10MB string"}, does it treats the pre-serialized JSON string as a simple string value and doesn't count the string's content toward the MaxJsonLength limit - only the JSON structural overhead (property names, brackets, etc.) is counted? Otherwise I don't understand why it is not breaking!?