Click here to Skip to main content
13,050,319 members (132,122 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Good Morning all,
I'm having trouble with a web service I've written which returns JSON. When the service is called I am getting a MaxJsonLength exceeded error (length is about 172k including JSON syntax, or 44k without, not sure which is relevant?). I have tried to set the max length to my JavaScriptSerializer within my WebMethod, but it doesn't seem to make any difference, here is my code :-

JavaScriptSerializer js = new JavaScriptSerializer();
                js.MaxJsonLength = Int32.MaxValue; //I have tried multiple values
                string strJSON = js.Serialize(JaggedArray);
                return strJSON;

if I step through in debug, the max length appears to be set, and if I call the method from the .asmx the results come back fine, the error only occurs when I call the method from my page via a jQuery ajax call.

can any one help?

Posted 14-Nov-10 22:48pm
Updated 14-Nov-10 22:49pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Apparently adding the following at the very end of my web config sorted my problem, why, when there was none originally set in the config, my maxJsonLength hard coded in the web method didn't work I have no idea, but never mind hey? :doh:

                <jsonSerialization maxJsonLength="500000"/>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 15 Nov 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100