locked
solve the problem RRS feed

  • Question

  • User-1634604574 posted

    i have this error

    The JSON request was too large to be deserialized

    i wrote this code but is not working

    <appSettings>
          <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
      </appSettings>
    Sunday, February 3, 2019 4:59 AM

All replies

  • User753101303 posted

    Hi,

    Maybe it's even higher? I would double this value each time to see if it ends up by "solving" the issue (or if the error message changes to something else). If confirmed you may want then to investigate if this is really expected and needed.

    Or it's something else. You are posting tons of form fields ?

    Sunday, February 3, 2019 3:02 PM
  • User-474980206 posted
    MaxJsonDeserializerMembers only increases the number of properties, not max size. There is no web.config setting for what you want (only for web.services). But you can increase the max using MaxJsonLength property of the JsonResult. This mean you return a JsonResult rather than use the Json helper method.
    Sunday, February 3, 2019 7:53 PM
  • User-1634604574 posted

    can you give a simple example about it view and controller

    Monday, February 4, 2019 8:34 AM
  • User-474980206 posted

    // return Json(myData);

    return new JsonResult {
        Data = mydata,
        MaxJsonLength = 100000
    }

    Monday, February 4, 2019 4:06 PM
  • User-1038772411 posted

    Please First Refere my answer Link for besic solution. if already done with this solution and still not getting proper solution so we can create JsonValueProviderFactory with a custom one. Below i provide code please use it properly its work fine for you.

    public sealed class JsonDotNetValueProviderFactory : ValueProviderFactory
    {
       public override IValueProvider GetValueProvider(ControllerContext controllerContext)
       {
            if (controllerContext == null)
                throw new ArgumentNullException("controllerContext");
    
            if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
                return null;
    
            var reader = new StreamReader(controllerContext.HttpContext.Request.InputStream);
            var bodyText = reader.ReadToEnd();
    
            return String.IsNullOrEmpty(bodyText) ? null : new DictionaryValueProvider<object>(JsonConvert.DeserializeObject<ExpandoObject>(bodyText, new ExpandoObjectConverter()) , CultureInfo.CurrentCulture);
        }
    }

    -----------------------------------------------------------------------------------------------------------------------------------------
    And in your Application_Start:

    ValueProviderFactories.Factories.Remove(ValueProviderFactories.Factories.OfType<JsonValueProviderFactory>().FirstOrDefault()); ValueProviderFactories.Factories.Add(new JsonDotNetValueProviderFactory());
    -----------------------------------------------------------------------------------------------------------------------------------------
    And if you want to stick with the default factory which uses the JavaScriptSerializer class you could adjust the maxJsonLength property in your web.config:

    <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="2147483644"/> </webServices> </scripting> </system.web.extensions>
    Thursday, February 7, 2019 6:25 AM