0
//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!?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.