C# Can';t设置最大JSONLENGTH

C# Can';t设置最大JSONLENGTH,c#,asp.net-mvc,json,C#,Asp.net Mvc,Json,我得到了这个错误: 内部服务器错误:使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了maxJsonLength属性上设置的值 我在谷歌上搜索了这方面的答案,找到了两个答案,这两个答案似乎都不适合我。我曾尝试将maxJsonLength设置添加到web.config,但被忽略。此外,我还尝试在C代码中设置MaxJsonLength=int.MaxValue;但是我使用的是MVC2.0,它似乎只适用于MVC4?有人能帮我正确设置maxJsonLen

我得到了这个错误:

内部服务器错误:使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了maxJsonLength属性上设置的值

我在谷歌上搜索了这方面的答案,找到了两个答案,这两个答案似乎都不适合我。我曾尝试将maxJsonLength设置添加到web.config,但被忽略。此外,我还尝试在C代码中设置MaxJsonLength=int.MaxValue;但是我使用的是MVC2.0,它似乎只适用于MVC4?有人能帮我正确设置maxJsonLength属性吗?这就是我得到错误的地方

 public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        var result = filterContext.Result as ViewResult;
        if (result == null)
        {
            return;
        }

        var jsonResult = new JsonResult
                             {
                              Data = result.ViewData.Model, 
                              JsonRequestBehavior = JsonRequestBehavior.AllowGet
                             };


        filterContext.Result = jsonResult;
    }

我不确定它是否有效,但我找到了一些解决方案,请在下面尝试

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

我不确定它是否有效,但我找到了一些解决方案,请在下面尝试

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

明白了,使用下面的代码

 public ActionResult MyFancyMethod()
 {
     var serializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
     var result = new ContentResult
     {
         Content = serializer.Serialize(myBigData),
         ContentType = "application/json"
     };
     return result;
}

明白了,使用下面的代码

 public ActionResult MyFancyMethod()
 {
     var serializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
     var result = new ContentResult
     {
         Content = serializer.Serialize(myBigData),
         ContentType = "application/json"
     };
     return result;
}

我尝试了这两种选择。Web.config选项被忽略,除非我做错了什么,否则MVC2似乎没有可用的MaxJsonLength属性。第二个选项修复了它,meI尝试了这两个选项。Web.config选项被忽略,除非我做错了什么,否则MVC2似乎没有可用的MaxJsonLength属性。第二个选项为我修复了它