0

I'have project in Visual Studio in Framework 4.5.

It is a ASP.NET MVC 4 WebApllication. I'm using JSON to get a lot of data. But when i execute it, it gives me that error: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

So, i want to modify max json length with this code:

 protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior)
    {
        return new JsonResult()
        {
            Data = data,
            ContentType = contentType,
            ContentEncoding = contentEncoding,
            JsonRequestBehavior = behavior,
            MaxJsonLength = Int32.MaxValue 
        };
    }

But i can't, because I get an error in line **MaxJsonLength = Int32.MaxValue **

Error is: System.Web.Mvc.JsonResult' does not contain a definition for 'MaxJsonLength

I have these references in class of controller:

  • using System;
  • using System.Collections.Generic;
  • using System.Linq;
  • using System.Web;
  • using System.Web.Mvc;
  • using WebserviceIPAD.Areas.Api.Models;
  • using System.Web.Script.Serialization;

But still getting an error: System.Web.Mvc.JsonResult' does not contain a definition for 'MaxJsonLength

Any one knows if I have to import more references?

Thanks.

enter image description here

HaOx
  • 1,839
  • 6
  • 26
  • 36

2 Answers2

1

Can I set an unlimited length for maxJsonLength in web.config?

It can be set in the config:

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 
Community
  • 1
  • 1
lloyd christmas
  • 556
  • 1
  • 4
  • 16
  • It doesn't works for me. I have these lines in web.config but error still appears: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. – HaOx Feb 14 '15 at 15:20
  • 1
    The max you can set it to is 2147483644. Is your data larger than that? – lloyd christmas Feb 14 '15 at 15:27
0

I just found a solution. I have created new project, every classes and configuration one more time. And know without any problem I can use MaxJsonLength.

Thanks for every one for suggestions.

HaOx
  • 1,839
  • 6
  • 26
  • 36