Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET JSON
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?
 
Cheers
Gib
Posted 14-Nov-10 23:48pm
Gibb3h490
Edited 14-Nov-10 23:49pm
v2

1 solution

Rate this: bad
good
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? D'Oh! | :doh:
 
<system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="500000"/>
            </webServices>
        </scripting>
    </system.web.extensions>
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 15 Nov 2010
Copyright © CodeProject, 1999-2014
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