Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC4错误:字符串长度超过maxJsonLength属性上设置的值_C#_Json_Web Services_Asp.net Mvc 4 - Fatal编程技术网

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

C# MVC4错误:字符串长度超过maxJsonLength属性上设置的值,c#,json,web-services,asp.net-mvc-4,C#,Json,Web Services,Asp.net Mvc 4,我试图使用JSON JavaScriptSerializer反序列化一个字符串过大的简历。我得到了这个错误 使用JSON进行序列化或反序列化时出错 JavaScriptSerializer。字符串的长度超过了设置的值 在maxJsonLength属性上 我已经将maxJsonLength属性添加到2147483644,但它仍然不起作用 <system.web.extensions> <scripting> <webServices>

我试图使用JSON JavaScriptSerializer反序列化一个字符串过大的简历。我得到了这个错误

使用JSON进行序列化或反序列化时出错 JavaScriptSerializer。字符串的长度超过了设置的值 在maxJsonLength属性上

我已经将maxJsonLength属性添加到2147483644,但它仍然不起作用

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

我已经这样解决了。这对我来说很好

JavaScriptSerializer jsSerializer = new JavaScriptSerializer() { MaxJsonLength = 86753090 }; var myobj = jsSerializer.Deserialize<List<List<CandidateResume>>>(description);
基于这篇文章

尝试以下配置,这比在代码中硬编码值更好。您的配置缺少一个部分

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="2147483647"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration>
已编辑,因为它看起来也像是在使用mvc4。请将以下内容添加到web config appsetting部分

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

我的解决方案是创建这个类:

public class LargeJsonResult : JsonResult
{
    public LargeJsonResult()
        : base()
    {
        this.MaxJsonLength = Int32.MaxValue;
    }
}
然后,在控制器操作中,我只是:

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

仅此而已。

我已经用这种方法解决了JavaScriptSerializer jsSerializer=new JavaScriptSerializer{MaxJsonLength=86753090};var myobj=jsSerializer.Deserializedescription;这个答案是最清楚的。我知道你几个月前就发布了这个,也许你已经看到了:这是针对web服务的。这篇文章专门针对MVC4。@JimSpeaker回答更新,他的标签最初让我困惑,因为他说的是web服务,但从外观上看,他只想要mvc解决方案。
public class LargeJsonResult : JsonResult
{
    public LargeJsonResult()
        : base()
    {
        this.MaxJsonLength = Int32.MaxValue;
    }
}
return new LargeJsonResult { Data = grid, JsonRequestBehavior = JsonRequestBehavior.AllowGet };