You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$10
For Premium members:
In this article you will learn how to handle larger JSON String Values in .NET and avoiding exceptions.
Working with JSON within Web Services recently has become the latest and greatest simply because it plays so nicely with others and can often be very easily serialized and deserialized to fit your needs. There is just something rewarding about having a massive collection of complex objects that can be throw into a simple string and passed across however you see fit and then completely regenerated in its original collection in just a handful of code. However sometimes these strings can get big and I mean really big, like exceeding default values big and when this happens, exceptions happen. This post will cover a few ways that you can prevent a nasty InvalidOperationException that may look something like this with ease: The Problem You decide that paging data is for losers and decide to pull a graph of all of the data within your database, which will hypothetically contains thousands of complex objects, each with additional properties of their own. If your dataset is large enough, you’ll find yourself quickly exceeding the bounds that your Serializer can handle and you’ll be met with an exception and no data. The Solution There are three basic methods of handling this depending on your current environment:
Option I: The MaxJsonLength Property for handling JSON in Web Services The MaxJsonLength property which can be set within the web.config of your application controls the maximum size of the JSON strings that are accepted by the JsonSerializerclass. The default value is 102400 characters. In order to increase the size of this value – you can just add the following code to your web.config file and set it to the value that you desire:
.NET Interview Questions and Answer: Practical Implementation