简体   繁体   English

MVC4错误:字符串的长度超过了在maxJsonLength属性上设置的值

[英]MVC4 error: The length of the string exceeds the value set on the maxJsonLength property

I am trying to deserialization a Resume which one string too large using the JSON JavaScriptSerializer. 我正在尝试使用JSON JavaScriptSerializer反序列化一个字符串太大的Resume。 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." “使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了在maxJsonLength属性上设置的值。”

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. 我已经将maxJsonLength属性添加到2147483644,但是它仍然不起作用。

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

I have solved this way . 我已经解决了这种方式。 Its working fine for me . 它对我来说很好。

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

Based on this post Can I set an unlimited length for maxJsonLength in web.config? 根据这篇文章, 我可以在web.config中为maxJsonLength设置无限长度吗?

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. 由于它看起来像您正在使用mvc4一样被编辑,将以下内容添加到您的Web config appsetting部分。

  <appSettings>
    <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
  </appSettings>

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. 就这样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 字符串的长度超过了 mvc 中 maxjsonlength 属性上设置的值 - the length of the string exceeds the value set on the maxjsonlength property in mvc 字符串的长度超过maxJsonLength属性上设置的值 - length of the string exceeds the value set on the maxJsonLength property 错误“字符串的长度超过了 maxJsonLength 属性上设置的值。” - Error 'The length of the string exceeds the value set on the maxJsonLength property.' 字符串的长度超过maxJsonLength属性c上设置的值。 - The length of the string exceeds the value set on the maxJsonLength property.c# 正在检测字符串的长度超过在服务器上的maxJsonLength属性上设置的值 - Detecting The length of the string exceeds the value set on the maxJsonLength property at the server 我收到“字符串的长度超过 maxJsonLength 属性上设置的值” - I am getting a “The length of the string exceeds the value set on the maxJsonLength property” 使用JSON JavaScriptSerializer时发生错误“字符串的长度超过了在maxJsonLength属性上设置的值” - Error when using JSON JavaScriptSerializer “The length of the string exceeds the value set on the maxJsonLength property” 尝试将部分视图转换为字符串时,“字符串的长度超出了在maxJsonLength属性上设置的值。” - “The length of the string exceeds the value set on the maxJsonLength property.” when trying to convert a partial view to string ASP.Net WebForm c#Web服务-字符串的长度超过在maxJsonLength属性上设置的值 - ASP.Net WebForm c# WebService - The length of the string exceeds the value set on the maxJsonLength property MVC maxJsonLength错误 - MVC maxJsonLength error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM