Click here to Skip to main content
15,746,107 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?

Updated 14-Nov-10 22:49pm

1 solution

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"/>
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900