chhaya_patel chhaya_patel - 1 year ago 100
JSON Question

Getting error while serializing using JavaScriptSerializer in c#

When I am serializing using JavaScriptSerializer in wcf service it gives me below error for defined code.


DataCollection<Entity> detailqueryentityCollection = _serviceProxy.RetrieveMultiple(detailquery).Entities;
if (detailqueryentityCollection.Count > 0)
listdata = new JavaScriptSerializer().Serialize(detailqueryentityCollection);


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

I also add below code in web.config but it doesn't work.

<jsonSerialization maxJsonLength="500000000"/>

Please suggest me any solutions.

Answer Source

When instantiating the class yourself, you need to add the value to the MaxJsonLength property of the class:

var jss = new JavaScriptSerializer();
jss.MaxJsonLength = 500000000;
listData = jss.Serialize(detailqueryentityCollection);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download