1

I am trying to deserialization a Resume which one string too large using the JSON JavaScriptSerializer. I am getting this error.

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

HttpResponseMessage messge = client.GetAsync("ladders/get/d381241a0ad596d4bf02f441e75d1891fcc482e607c751e3978bc0adea6a9d99").Result;
string result = messge.Content.ReadAsStringAsync().Result;
string  description = result;

     JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
     var myobj = jsSerializer.Deserialize<List<List<CandidateResume>>>(description); 

This is my class

 public class CandidateResume
        {

            public string name { get; set; }
            public string url { get; set; }
            public string summary { get; set; }
            public string role { get; set; }
            public string compensation { get; set; }
            public string education { get; set; }
            public string expertise { get; set; }
            public string years { get; set; }
            public string relocation { get; set; }
            public string resume { get; set; }
            public string resumeExtension { get; set; }
            public string resumeMimeType { get; set; }

        }

I've added the maxJsonLength property to 2147483644, but it still doesn't work.

 <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483644"/>
      </webServices>
    </scripting>
  </system.web.extensions>
Letoncse
  • 702
  • 4
  • 15
  • 36
  • I have solved this way JavaScriptSerializer jsSerializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 }; var myobj = jsSerializer.Deserialize>>(description); – Letoncse Feb 06 '15 at 19:01
  • This answer is the cleanest. I realize you posted this months ago, and perhaps you've seen this already: http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config/12278956#12278956 – Jim Speaker Sep 09 '15 at 23:07

3 Answers3

0

I have solved this way . Its working fine for me .

JavaScriptSerializer jsSerializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 }; var myobj = jsSerializer.Deserialize<List<List<CandidateResume>>>(description);
Letoncse
  • 702
  • 4
  • 15
  • 36
0

Based on this post Can I set an unlimited length for maxJsonLength in web.config?

Try the following configuration, this is better practice than hardcoding the value in the code. Your config is missing one section

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

Edited since it also looks like you are using mvc4 add the following to your web config appsetting section.

  <appSettings>
    <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
  </appSettings>
Community
  • 1
  • 1
Marko
  • 2,734
  • 24
  • 24
  • That's for web services. This post specifically addresses MVC4. – Jim Speaker Sep 09 '15 at 22:44
  • @JimSpeaker answer updated, his tags confused me originally as he states web services but from the looks of it he wants only the mvc solution. – Marko Sep 11 '15 at 22:23
0

My solution was to create this class:

public class LargeJsonResult : JsonResult
{
    public LargeJsonResult()
        : base()
    {
        this.MaxJsonLength = Int32.MaxValue;
    }
}

Then, in controller action, I just did:

return new LargeJsonResult { Data = grid, JsonRequestBehavior = JsonRequestBehavior.AllowGet };

That's all.

jstuardo
  • 3,901
  • 14
  • 61
  • 136