A while ago I was building a tree and I decided that it would be a great idea to load its branches on demand.
At the moment, the best way I could figure out to do this was using some
JavaScript and my beloved PageMethods.
After coding and coding I got it working, and it worked wonderfully... The day came when my tree was moved to the production environment, where it would use a big data hierarchy.
The main issue was that some of the branches loaded lots of data, and when I expanded one of them I got the "Maximum length exceeded" error.
Since the branches where being loaded on demand, the PageMethod was retrieving all the HTML the branch needed, and, in some cases, this would exceed the
default maximum JSON length
After some googling I found there's a simple way to increase this length by changing a key in the web.config:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="400000" />
</webServices>
</scripting>
</system.web.extensions>
In this example I changed it to 400.000 characters, you should calculate the amount of data you need to transfer, but have in mind there might be some bytes of overhead.