相关疑难解决方法(0)

获取"JSON请求太大而无法反序列化"

我收到此错误:

JSON请求太大而无法反序列化.

这是发生这种情况的场景.我有一类国家,其中包含该国的航运港口清单

public class Country
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<Port> Ports { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我在客户端使用KnockoutJS进行级联下拉.所以我们有两个下拉列表,其中第一个是国家,第二个是该国家的港口.

到目前为止一切正常,这是我的客户端脚本:

var k1 = k1 || {};
$(document).ready(function () {

    k1.MarketInfoItem = function (removeable) {
        var self = this;
        self.CountryOfLoadingId = ko.observable();
        self.PortOfLoadingId = ko.observable();
        self.CountryOfDestinationId = ko.observable();
        self.PortOfDestinationId = ko.observable();  
    };

    k1.viewModel = function () {
        var marketInfoItems = ko.observableArray([]),
            countries = ko.observableArray([]),

            saveMarketInfo = function () {
                var …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc knockout.js

199
推荐指数
1
解决办法
8万
查看次数

JsonValueProviderFactory抛出"请求太大"

我得到一个例外,即JSON请求太大而无法反序列化.

它来自JsonValueProviderFactory ....

MVC App目前有一个使用Json.Net的自定义模型绑定器,对于反序列化json数据没有问题.但是我假设默认的JSON值提供程序正在绊倒?或者内置了一些奇怪的限制?

可能与最新版本的MVC4有关,因为使用之前的MVC4版本时,大量的JSON没有问题.

那么,有没有办法改变实际json值绑定器的设置?

经过http://haacked.com/archive/2011/06/30/whatrsquos-the-difference-between-a-value-provider-and-model-binder.aspx

我得到的印象是,它是一些自定义的东西,把它变成一个字典....我找不到任何与它相关的源代码或者我是否可以更改任何设置?

或者我可以使用另一种ValueBinder吗?

或任何其他选择?

Server Error in '/' Application.
The JSON request was too large to be deserialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The JSON request was too large to be deserialized.

Source Error:

An unhandled exception was generated during the execution of …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc json.net asp.net-mvc-4

33
推荐指数
2
解决办法
2万
查看次数

ASP.NET MVC4序列化或反序列化JSON期间出错 - 大数据

我写信给你网站上有错误:使用JSON JavaScriptSerializer进行序列化或反序列化时出错.字符串的长度超过maxJsonLength属性上设置的值.

使用的技术:C#,.NET FW 4.5,ASP.NET MVC4和Lint to SQL,Kendo UI(显示结果的网格).

我想返回(就Json而言)一大组数据 - 实际上我有50,000条记录(不会发生超过250,000条记录)

我尝试在web.config中放大maxJsonLength和将来启用压缩 - 同样的错误:

  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="10485760"/>
      </webServices>
      <scriptResourceHandler enableCompression="true" enableCaching="true"/>
    </scripting>
  </system.web.extensions>
Run Code Online (Sandbox Code Playgroud)

接下来我尝试在C#类中重写return方法 - 同样的错误:a)默认

public JsonResult GetResult()
{
  // execute query for get result
  var myBigData = from ......
      select new
      {
          .......
      };

  // return result
  return this.Json(myBigData, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)

b)重写(仍然是错误的)

public JsonResult GetResult()
{
  // execute query for get result
  var myBigData = from ......
      select new
      {
          .......
      };

  // return result …
Run Code Online (Sandbox Code Playgroud)

c# json jsonserializer large-data asp.net-mvc-4

3
推荐指数
1
解决办法
3133
查看次数