We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Error during serialization or deserialization using the JSON JavaScriptSerializer

Hi,
I am trying to display hierarchical data in treegrid and when the records is large, I got the following error:

"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. "

I read some discussions about this issue in the forum, but it seems those solutions are not for asp.net mvc 5 and treegrid, which I am working with.
Are there other solutions that works for asp.net mvc 5 and treegrid?
Thanks,

Harry

3 Replies

MK Mahalakshmi Karthikeyan Syncfusion Team July 10, 2015 12:37 PM UTC

Hi Harry,

In our ASP.NET MVC Treegrid, we have rendered all the html elements in clientside and we have passed the data to the control from serverside to clientside as Json data by serializing it. And we have used the defaultMaxJsonLengthvalue (2097152characters, which is equivalent to 4MB of Unicode string data) of the JavaScriptSerializer which is a fixed universal standard length for serializing the data, in our implementation.

So we have to create a custom serializer to serialize the data Source if the data exceeds its limit, this can be done as follows.

using Newtonsoft;

using Syncfusion.JavaScript.Shared.Serializer;

//…

public ActionResult Index() {

        var DataSource = GanttDataSource.GetData();

        DataManagerConverter.Serializer = new DMSerial();

        ViewBag.datasource = DataSource;

        return View();

    }

    //…

public class DMSerial: IDataSourceSerializer {

    public string Serialize(object obj) {

        var str = Newtonsoft.Json.JsonConvert.SerializeObject(obj);

        return str;

    }

}

We have also prepared a sample based on this and you can find the sample under the following location:

Sample: http://www.syncfusion.com/downloads/support/forum/119571/ze/LargeData888429426

Please let us know if you need further assistance on this.

Regards,

Mahalakshmi K.



HZ Harry Zheng July 10, 2015 01:59 PM UTC

Hi Mahalakshmi,

Thank you for the solution. It works great!

Regards,

Harry


MK Mahalakshmi Karthikeyan Syncfusion Team July 13, 2015 05:46 PM UTC

Hi Harry,
Thanks for the update. We are happy to assist you.
Please let us know if you need more information on this.
Regards,
Mahalakshmi K.

Loader.
Live Chat Icon For mobile
Up arrow icon