1

I have a large set of data and it could vary in size. I ran into an error with MaxJsonLength when the data was serialised and passed to JS from C#.

I found a fix here and it works fine. But i'm curious to if it's bad to set the number too high? There is obviously a reason it defaults to 102400 (100k).

Would it be possible for me to find out the rough size of my data in JavaScriptSerializer string length, so i could bring the number in the config file down?

Thanks

Community
  • 1
  • 1
SammyG
  • 299
  • 1
  • 4
  • 15

1 Answers1

1

When I set this property, our JSON is unicode (two bytes per char), so we use the following for an eleven MB JSON file:

1024*1024*22

Which gives us 23068672.

So, my example is as follows - if you count the actual length of your JSON (11MB), double it if unicode (22MB) then workout the bytes (1024*1024).

To get the length of the JSON, simply count the bytes from the JSON string:

var count = Encoding.UTF8.GetBytes(json).Length;

  • Thanks for the help. I have followed what you have said and I have done this to the array in c# before it is sent and handled by the JavaScriptSerializer thats automatic within asp.net. I have done this `JavaScriptSerializer json = new JavaScriptSerializer(); json.Serialize(data); int a = Encoding.UTF8.GetBytes(json.ToString()).Length;` and it gives me 52 this worked out to be 54525952 using your calculation. however i tested it and reduced it by one and added it to config file. Still the program worked. – SammyG Jun 18 '15 at 13:19