1

In one of my controller actions,when I return a more than 10000 rows JsonResult to the view. I will get the below exceptions.

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. enter image description here

I have setted the maxJsonLength property in the web.config to a higher value unfortunately does not show any effect like below:

  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483644"/>
      </webServices>
    </scripting>
  </system.web.extensions>

And I also set the MaxJsonLength when I used Json class like below:

    public JsonResult GetList(GridPager pager, string queryStr)
    {
        List<SysExceptionModel> list = _exceptionBLL.GetList(ref pager, queryStr);
        var json = new
        {
            total = pager.totalRows,
            rows = list.ToArray()
        };

        var jsonresults = Json(json);
        jsonresults.MaxJsonLength = int.MaxValue;
        return jsonresults;
    }

These two settings would not help me. I was confused.

one row is like below:

0000688A-85F5-4F72-BE86-85BCADED2DE NULL BBBB BBBB BBBB BBBB BBBB 2015-10-22 02:27:38.000

2
  • For your image, use serializer.MaxJsonLength = Int32.MaxValue; before serializing data. Try var jsonresults = Json(json, JsonRequestBehavior.AllowGet); for code snippet. Commented Oct 22, 2015 at 11:06
  • Yes, It do works.Appreciate. Commented Oct 23, 2015 at 2:01

2 Answers 2

1

Try to use NewtonSoft.Json library instead. Or try to override the JsonResult like in this example: CustomJsonResult

Setting the max jsonSerialization in the xml does not always work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much.Appreciate.
0

In your first example, try setting the MaxJsonLength property directly on the JavaScriptSerializer instance. Per the documentation, it does not use the jsonSerialization element of the configuration file when you explicitly create an instance of the serializer.

JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = int.MaxValue;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.