Using JSON – Some observations


When using JSON with Web Services (classic web service or WCF service), you might get an error “JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.” when your json string is too big. If you are using JavaScriptSerializer class to serilaize your object, then there is a property ser.MaxJsonLength that you can set to allow for more size. But somehow, I still got the error, and I had to make that setting in web.config file. If you are using DataContractJsonSerializer class (using System.Runtime.Serialization.Json namespace), then you don’t have MaxJsonLength property for that class, but adding configuration settings in web.config works like a charm.

Here is how you change MaxJsonLength using web.config:

  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength=”2147483647″></jsonSerialization>
      </webServices>
    </scripting>
  </system.web.extensions>

 
Cheers!

5 comments

      • Narasimha

        Thanks boss
        for giving the solution jss.MaxJsonLength = Int32.MaxValue;
        thanks i’m so happy with line of code no need to add code in web.config

        this line is enough jss.MaxJsonLength = Int32.MaxValue;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s