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

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

 

I am getting the above error sometimes while making JSON webservice call from Javascript. But i checked my web.config, i haven't set any maxJsonLength property setting. Still i am getting this error. Any reason behind in it?

 

asked Jan 28, 2013 by inquirer (710 points)
    

1 Answer

0 votes
 
Best answer

 

Whether setting exist or not. By default it will be limited to 4 MB maxJsonLength. So better add the below entry into your web.config

  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="10485760"/>
      </webServices>
      <scriptResourceHandler enableCompression="true" enableCaching="true"/>
    </scripting>
  </system.web.extensions>

The above entry will change the maxJsonLength to 10 MB. This must fix your problem. Still if you want to increase the size then change the value.

 

But my suggestion will be better to use pagination when it increases more than 10 MB. To avoid more traffic between client and server in one single call.

answered Jan 28, 2013 by analyst (3,200 points)
selected Jan 28, 2013 by inquirer
...