The string is longer than the value specified for the maxJsonLength property

I have a .Net Web service (.asmx) that will return a Json string to my client. However, some of my data is really big, and I sometimes get this error.

The string is longer than the value specified for the maxJsonLength property.

I changed the maxJsonLength property to 2147483644, but it still does not work. Please help ... Thanks.

<system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="2147483644"/> </webServices> </scripting> </system.web.extensions> [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetData(string login) { // throw an error on this line... string result = new JavaScriptSerializer().Serialize(service.GetData(login)); Context.Response.Write(result); } 
+5
source share
1 answer

Thanks to suggestions from Ed Gibbs and @NextInLine. I made a fix as shown below and now it works like a charm. I also removed the "system.web.extensions" part from my web.config

 [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetData(string login) { // when the amount of data return is huge var serializer = new JavaScriptSerializer(); // we need to do this. serializer.MaxJsonLength = Int32.MaxValue; var result = serializer.Serialize(service.GetData(login)); Context.Response.Write(result); } 
+7
source

Source: https://habr.com/ru/post/1212141/


All Articles