我正在使用jQuery的自动完成功能。当我尝试检索超过17000条记录的列表(每条记录的长度不超过10个字符)时,它超过了长度,并引发错误:
异常信息:
异常类型:InvalidOperationException
异常消息:使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了在maxJsonLength属性上设置的值。
我可以设置无限长度maxJsonLength的web.config?如果没有,我可以设置的最大长度是多少?
我正在使用jQuery的自动完成功能。当我尝试检索超过17000条记录的列表(每条记录的长度不超过10个字符)时,它超过了长度,并引发错误:
异常信息:
异常类型:InvalidOperationException
异常消息:使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了在maxJsonLength属性上设置的值。
我可以设置无限长度maxJsonLength的web.config?如果没有,我可以设置的最大长度是多少?
Answers:
注意:此答案仅适用于Web服务,如果要从Controller方法返回JSON,请确保还阅读以下SO答案:https : //stackoverflow.com/a/7207539/1246870
所述MaxJsonLength属性不能是无限的,是整数属性默认为102400(10万)。
您可以MaxJsonLength在web.config上设置属性:
<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 2147483647@depsart和@Descár指出的。
                    return Json()或其他东西时遇到此问题,请注意以下@David Murdoch的回答
                    如果您使用的是MVC 4,请确保也检查出此答案。
如果您仍然收到错误:
maxJsonLength在web.config属性为其最大值之后您的问题可能是:
MaxJsonLength属性的值仅适用于内部JavaScriptSerializer实例,异步通信层使用该实例来调用Web服务方法。(MSDN:ScriptingJsonSerializationSection.MaxJsonLength属性)
基本上,“内部” JavaScriptSerializer尊重maxJsonLength从Web方法调用时的值;直接使用的一个JavaScriptSerializer(或使用通过MVC行动的方法/控制器)不不尊重maxJsonLength属性,至少没有从systemWebExtensions.scripting.webServices.jsonSerializationweb.config中的部分。
解决方法是,您可以在Controller内(或实际上在任何地方)执行以下操作:
var serializer = new JavaScriptSerializer();
// For simplicity just use Int32's max value.
// You could always read the value from the config section mentioned above.
serializer.MaxJsonLength = Int32.MaxValue;
var resultData = new { Value = "foo", Text = "var" };
var result = new ContentResult{
    Content = serializer.Serialize(resultData),
    ContentType = "application/json"
};
return result;这个答案是我对这个asp.net论坛答案的解释。
Json()在asp.net mvc中使用动作结果方法。
                    在MVC 4中,您可以执行以下操作:
protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior)
{
    return new JsonResult()
    {
        Data = data,
        ContentType = contentType,
        ContentEncoding = contentEncoding,
        JsonRequestBehavior = behavior,
        MaxJsonLength = Int32.MaxValue
    };
}在您的控制器中。
加成:
对于那些对您需要指定的参数感到困惑的人,呼叫可能看起来像这样:
Json(
    new {
        field1 = true,
        field2 = "value"
        },
    "application/json",
    Encoding.UTF8,
    JsonRequestBehavior.AllowGet
);您可以在web.config文件中配置json请求的最大长度:
<configuration>
    <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="....">
                </jsonSerialization>
            </webServices>
        </scripting>
    </system.web.extensions>
</configuration>maxJsonLength的默认值为102400。有关更多详细信息,请参见此MSDN页面:http : //msdn.microsoft.com/zh-cn/library/bb763183.aspx
如果在进行如下所示的web.config设置后仍然出现错误:
<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 我通过以下方法解决了它:
   public ActionResult/JsonResult getData()
   {
      var jsonResult = Json(superlargedata, JsonRequestBehavior.AllowGet);
      jsonResult.MaxJsonLength = int.MaxValue;
      return jsonResult;
    }我希望这会有所帮助。
我在ASP.NET Web窗体中遇到此问题。它完全忽略了web.config文件的设置,所以我这样做了:
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        serializer.MaxJsonLength = Int32.MaxValue; 
        return serializer.Serialize(response);当然,总的来说,这是可怕的做法。如果要通过Web服务调用发送大量数据,则应考虑使用其他方法。
我修好了它。
//your Json data here
string json_object="........";
JavaScriptSerializer jsJson = new JavaScriptSerializer();
jsJson.MaxJsonLength = 2147483644;
MyClass obj = jsJson.Deserialize<MyClass>(json_object);效果很好。
我遵循残留的答案,并得到以下解决方案:
当我需要将大型json发布到控制器中的操作时,我将得到著名的“使用JSON JavaScriptSerializer进行反序列化期间的错误。字符串的长度超过了在maxJsonLength属性上设置的值。\ r \ n参数名称:input价值提供者”。
我所做的是创建一个新的ValueProviderFactory,LargeJsonValueProviderFactory,并在GetDeserializedObject方法中设置MaxJsonLength = Int32.MaxValue。
public sealed class LargeJsonValueProviderFactory : ValueProviderFactory
{
private static void AddToBackingStore(LargeJsonValueProviderFactory.EntryLimitedDictionary backingStore, string prefix, object value)
{
    IDictionary<string, object> dictionary = value as IDictionary<string, object>;
    if (dictionary != null)
    {
        foreach (KeyValuePair<string, object> keyValuePair in (IEnumerable<KeyValuePair<string, object>>) dictionary)
            LargeJsonValueProviderFactory.AddToBackingStore(backingStore, LargeJsonValueProviderFactory.MakePropertyKey(prefix, keyValuePair.Key), keyValuePair.Value);
    }
    else
    {
        IList list = value as IList;
        if (list != null)
        {
            for (int index = 0; index < list.Count; ++index)
                LargeJsonValueProviderFactory.AddToBackingStore(backingStore, LargeJsonValueProviderFactory.MakeArrayKey(prefix, index), list[index]);
        }
        else
            backingStore.Add(prefix, value);
    }
}
private static object GetDeserializedObject(ControllerContext controllerContext)
{
    if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
        return (object) null;
    string end = new StreamReader(controllerContext.HttpContext.Request.InputStream).ReadToEnd();
    if (string.IsNullOrEmpty(end))
        return (object) null;
    var serializer = new JavaScriptSerializer {MaxJsonLength = Int32.MaxValue};
    return serializer.DeserializeObject(end);
}
/// <summary>Returns a JSON value-provider object for the specified controller context.</summary>
/// <returns>A JSON value-provider object for the specified controller context.</returns>
/// <param name="controllerContext">The controller context.</param>
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
{
    if (controllerContext == null)
        throw new ArgumentNullException("controllerContext");
    object deserializedObject = LargeJsonValueProviderFactory.GetDeserializedObject(controllerContext);
    if (deserializedObject == null)
        return (IValueProvider) null;
    Dictionary<string, object> dictionary = new Dictionary<string, object>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
    LargeJsonValueProviderFactory.AddToBackingStore(new LargeJsonValueProviderFactory.EntryLimitedDictionary((IDictionary<string, object>) dictionary), string.Empty, deserializedObject);
    return (IValueProvider) new DictionaryValueProvider<object>((IDictionary<string, object>) dictionary, CultureInfo.CurrentCulture);
}
private static string MakeArrayKey(string prefix, int index)
{
    return prefix + "[" + index.ToString((IFormatProvider) CultureInfo.InvariantCulture) + "]";
}
private static string MakePropertyKey(string prefix, string propertyName)
{
    if (!string.IsNullOrEmpty(prefix))
        return prefix + "." + propertyName;
    return propertyName;
}
private class EntryLimitedDictionary
{
    private static int _maximumDepth = LargeJsonValueProviderFactory.EntryLimitedDictionary.GetMaximumDepth();
    private readonly IDictionary<string, object> _innerDictionary;
    private int _itemCount;
    public EntryLimitedDictionary(IDictionary<string, object> innerDictionary)
    {
        this._innerDictionary = innerDictionary;
    }
    public void Add(string key, object value)
    {
        if (++this._itemCount > LargeJsonValueProviderFactory.EntryLimitedDictionary._maximumDepth)
            throw new InvalidOperationException("JsonValueProviderFactory_RequestTooLarge");
        this._innerDictionary.Add(key, value);
    }
    private static int GetMaximumDepth()
    {
        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        if (appSettings != null)
        {
            string[] values = appSettings.GetValues("aspnet:MaxJsonDeserializerMembers");
            int result;
            if (values != null && values.Length > 0 && int.TryParse(values[0], out result))
                return result;
        }
        return 1000;
     }
  }
}然后,在Global.asax.cs的Application_Start方法中,将ValueProviderFactory替换为新的:
protected void Application_Start()
{
    ...
    //Add LargeJsonValueProviderFactory
    ValueProviderFactory jsonFactory = null;
    foreach (var factory in ValueProviderFactories.Factories)
    {
        if (factory.GetType().FullName == "System.Web.Mvc.JsonValueProviderFactory")
        {
            jsonFactory = factory;
            break;
        }
    }
    if (jsonFactory != null)
    {
        ValueProviderFactories.Factories.Remove(jsonFactory);
    }
    var largeJsonValueProviderFactory = new LargeJsonValueProviderFactory();
    ValueProviderFactories.Factories.Add(largeJsonValueProviderFactory);
}在将上述添加内容添加到web.config中之后,如果您获得“无法识别的配置部分system.web.extensions”。错误,然后尝试将其添加到部分的web.config中<ConfigSections>:
            <sectionGroup name="system.web.extensions" type="System.Web.Extensions">
              <sectionGroup name="scripting" type="System.Web.Extensions">
                    <sectionGroup name="webServices" type="System.Web.Extensions">
                          <section name="jsonSerialization" type="System.Web.Extensions"/>
                    </sectionGroup>
              </sectionGroup>
        </sectionGroup><section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>,如在此页面上所示:forums.asp.net/t/1446510.aspx/1
                    您可以将此行写入Controller
json.MaxJsonLength = 2147483644;您也可以将此行写入 web.config
<configuration>
  <system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483647">
            </jsonSerialization>
        </webServices>
    </scripting>
  </system.web.extensions>`
为了安全起见,请同时使用两者。
如果从MVC 的MiniProfiler中收到此错误,则可以通过将属性设置MiniProfiler.Settings.MaxJsonResponseSize为所需值来增加该值。默认情况下,此工具似乎忽略config中设置的值。
MiniProfiler.Settings.MaxJsonResponseSize = 104857600;只需在MVC的Action方法中设置MaxJsonLength属性即可
JsonResult json= Json(classObject, JsonRequestBehavior.AllowGet);
json.MaxJsonLength = int.MaxValue;
return json;一些属性魔术怎么样?
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class MaxJsonSizeAttribute : ActionFilterAttribute
{
    // Default: 10 MB worth of one byte chars
    private int maxLength = 10 * 1024 * 1024;
    public int MaxLength
    {
        set
        {
            if (value < 0) throw new ArgumentOutOfRangeException("value", "Value must be at least 0.");
            maxLength = value;
        }
        get { return maxLength; }
    }
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        JsonResult json = filterContext.Result as JsonResult;
        if (json != null)
        {
            if (maxLength == 0)
            {
                json.MaxJsonLength = int.MaxValue;
            }
            else
            {
                json.MaxJsonLength = maxLength;
            }
        }
    }
}然后,您可以使用全局过滤器配置或控制器/操作方式在全局应用它。
问题实际上是您是否真的需要返回17,000条记录?您打算如何处理浏览器中的所有数据?无论如何,用户不会滚动浏览17000行。
更好的方法是仅检索“前几个”记录,并根据需要加载更多记录。
您可以像其他人所说的那样在配置中进行设置,也可以在序列化程序的单个实例上进行设置,例如:
var js = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue };对于那些在JSON中会自动反序列化为模型绑定程序且太大的JSON的MVC3问题,这里提供了一个解决方案。
感谢http://blog.naver.com/techshare/100145191355和https://gist.github.com/DalSoft/1588818为我指出了执行此操作的正确方向。第一个站点上的最后一个链接包含该解决方案的完整源代码。
如果在View中遇到此类问题,则可以使用以下方法解决该问题。这里使用了Newtonsoft软件包。
@using Newtonsoft.Json
<script type="text/javascript">
    var partData = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Part));
</script> JsonResult result = Json(r);
 result.MaxJsonLength = Int32.MaxValue;
 result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
 return result;似乎没有“无限”值。默认值为2097152个字符,相当于4 MB的Unicode字符串数据。
正如已经观察到的,在浏览器中很难很好地使用17,000条记录。如果要提供聚合视图,则在服务器上进行聚合并仅在浏览器中传输摘要可能会更有效。例如,考虑文件系统浏览器,我们只看到树的顶部,然后在向下钻取时发出进一步的请求。每个请求中返回的记录数量相对较少。树视图演示文稿可以很好地用于大型结果集。
刚遇到这个。我正在获得6,000多个记录。刚决定我只做一些寻呼。像这样,我在MVC JsonResult端点中接受页码,该页码默认为0,因此没有必要,例如:
public JsonResult MyObjects(int pageNumber = 0)然后,而不是说:
return Json(_repository.MyObjects.ToList(), JsonRequestBehavior.AllowGet);我说:
return Json(_repository.MyObjects.OrderBy(obj => obj.ID).Skip(1000 * pageNumber).Take(1000).ToList(), JsonRequestBehavior.AllowGet);非常简单 然后,用JavaScript代替:
function myAJAXCallback(items) {
    // Do stuff here
}我反而说:
var pageNumber = 0;
function myAJAXCallback(items) {
    if(items.length == 1000)
        // Call same endpoint but add this to the end: '?pageNumber=' + ++pageNumber
    }
    // Do stuff here
}首先将您的记录附加到您对它们的处理中。或者只是等到所有呼叫结束并把结果拼凑在一起。
我解决了添加以下代码的问题:
String confString = HttpContext.Current.Request.ApplicationPath.ToString();
Configuration conf = WebConfigurationManager.OpenWebConfiguration(confString);
ScriptingJsonSerializationSection section = (ScriptingJsonSerializationSection)conf.GetSection("system.web.extensions/scripting/webServices/jsonSerialization");
section.MaxJsonLength = 6553600;
conf.Save();string confString = HttpContext.Request.ApplicationPath.ToString(); var conf = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(confString); var section = (System.Web.Configuration.ScriptingJsonSerializationSection)conf.GetSection("system.web.extensions/scripting/webServices/jsonSerialization"); section.MaxJsonLength = int.MaxValue; conf.Save();
                    替代ASP.NET MVC 5修复:
(我的方法类似于MFC的上述回答,但有一些小的更改)
我还没有准备好更改为Json.NET,就我而言,该错误是在请求期间发生的。在我的方案中,最好的方法是修改将JsonValueProviderFactory修订应用于全局项目的实际方法,并且可以通过编辑该global.cs文件来完成。
JsonValueProviderConfig.Config(ValueProviderFactories.Factories);添加一个web.config条目:
<add key="aspnet:MaxJsonLength" value="20971520" />然后创建以下两个类
public class JsonValueProviderConfig
{
    public static void Config(ValueProviderFactoryCollection factories)
    {
        var jsonProviderFactory = factories.OfType<JsonValueProviderFactory>().Single();
        factories.Remove(jsonProviderFactory);
        factories.Add(new CustomJsonValueProviderFactory());
    }
}这基本上是在中找到的默认实现的精确副本,System.Web.Mvc但添加了可配置的web.config appsetting值aspnet:MaxJsonLength。
public class CustomJsonValueProviderFactory : ValueProviderFactory
{
    /// <summary>Returns a JSON value-provider object for the specified controller context.</summary>
    /// <returns>A JSON value-provider object for the specified controller context.</returns>
    /// <param name="controllerContext">The controller context.</param>
    public override IValueProvider GetValueProvider(ControllerContext controllerContext)
    {
        if (controllerContext == null)
            throw new ArgumentNullException("controllerContext");
        object deserializedObject = CustomJsonValueProviderFactory.GetDeserializedObject(controllerContext);
        if (deserializedObject == null)
            return null;
        Dictionary<string, object> strs = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        CustomJsonValueProviderFactory.AddToBackingStore(new CustomJsonValueProviderFactory.EntryLimitedDictionary(strs), string.Empty, deserializedObject);
        return new DictionaryValueProvider<object>(strs, CultureInfo.CurrentCulture);
    }
    private static object GetDeserializedObject(ControllerContext controllerContext)
    {
        if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
            return null;
        string fullStreamString = (new StreamReader(controllerContext.HttpContext.Request.InputStream)).ReadToEnd();
        if (string.IsNullOrEmpty(fullStreamString))
            return null;
        var serializer = new JavaScriptSerializer()
        {
            MaxJsonLength = CustomJsonValueProviderFactory.GetMaxJsonLength()
        };
        return serializer.DeserializeObject(fullStreamString);
    }
    private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
    {
        IDictionary<string, object> strs = value as IDictionary<string, object>;
        if (strs != null)
        {
            foreach (KeyValuePair<string, object> keyValuePair in strs)
                CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakePropertyKey(prefix, keyValuePair.Key), keyValuePair.Value);
            return;
        }
        IList lists = value as IList;
        if (lists == null)
        {
            backingStore.Add(prefix, value);
            return;
        }
        for (int i = 0; i < lists.Count; i++)
        {
            CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakeArrayKey(prefix, i), lists[i]);
        }
    }
    private class EntryLimitedDictionary
    {
        private static int _maximumDepth;
        private readonly IDictionary<string, object> _innerDictionary;
        private int _itemCount;
        static EntryLimitedDictionary()
        {
            _maximumDepth = CustomJsonValueProviderFactory.GetMaximumDepth();
        }
        public EntryLimitedDictionary(IDictionary<string, object> innerDictionary)
        {
            this._innerDictionary = innerDictionary;
        }
        public void Add(string key, object value)
        {
            int num = this._itemCount + 1;
            this._itemCount = num;
            if (num > _maximumDepth)
            {
                throw new InvalidOperationException("The length of the string exceeds the value set on the maxJsonLength property.");
            }
            this._innerDictionary.Add(key, value);
        }
    }
    private static string MakeArrayKey(string prefix, int index)
    {
        return string.Concat(prefix, "[", index.ToString(CultureInfo.InvariantCulture), "]");
    }
    private static string MakePropertyKey(string prefix, string propertyName)
    {
        if (string.IsNullOrEmpty(prefix))
        {
            return propertyName;
        }
        return string.Concat(prefix, ".", propertyName);
    }
    private static int GetMaximumDepth()
    {
        int num;
        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        if (appSettings != null)
        {
            string[] values = appSettings.GetValues("aspnet:MaxJsonDeserializerMembers");
            if (values != null && values.Length != 0 && int.TryParse(values[0], out num))
            {
                return num;
            }
        }
        return 1000;
    }
    private static int GetMaxJsonLength()
    {
        int num;
        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        if (appSettings != null)
        {
            string[] values = appSettings.GetValues("aspnet:MaxJsonLength");
            if (values != null && values.Length != 0 && int.TryParse(values[0], out num))
            {
                return num;
            }
        }
        return 1000;
    }
}采用 lib\Newtonsoft.Json.dll
public string serializeObj(dynamic json) {        
    return JsonConvert.SerializeObject(json);
}WebForms UpdatePanel的解决方案:
将设置添加到Web.config:
<configuration>
  <appSettings>
    <add key="aspnet:UpdatePanelMaxScriptLength" value="2147483647" />
  </appSettings>
</configuration>https://support.microsoft.com/zh-CN/kb/981884
ScriptRegistrationManager 该类包含以下代码:
// Serialize the attributes to JSON and write them out
JavaScriptSerializer serializer = new JavaScriptSerializer();
// Dev10# 877767 - Allow configurable UpdatePanel script block length
// The default is JavaScriptSerializer.DefaultMaxJsonLength
if (AppSettings.UpdatePanelMaxScriptLength > 0) {
    serializer.MaxJsonLength = AppSettings.UpdatePanelMaxScriptLength;
}  
string attrText = serializer.Serialize(attrs);我们不需要任何服务器端更改。您只能通过web.config文件修改 此问题。这对我有所帮助。试试这个
<appSettings>
 <add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />
<add key="aspnet:UpdatePanelMaxScriptLength" value="2147483647" />
</appSettings>  
and   
<system.web.extensions>
<scripting>
  <webServices>
    <jsonSerialization maxJsonLength="2147483647"/>
  </webServices>
</scripting>修复ASP.NET MVC:如果只想修复引起问题的特定操作,则编写如下代码:
public JsonResult GetBigJson()
{
    var someBigObject = GetBigObject();
    return Json(someBigObject);
}您可以更改为:
public JsonResult GetBigJson()
{
    var someBigObject = GetBigObject();
    return new JsonResult()
    {
        Data = someBigObject,
        JsonRequestBehavior = JsonRequestBehavior.DenyGet,
        MaxJsonLength = int.MaxValue
    };
}而且功能应该相同,您可以返回更大的JSON作为响应。
基于ASP.NET MVC源代码的说明:您可以检查Controller.JsonASP.NET MVC 源代码中的方法
protected internal JsonResult Json(object data)
{
    return Json(data, null /* contentType */, null /* contentEncoding */, JsonRequestBehavior.DenyGet);
}它正在调用其他Controller.Json方法:
protected internal virtual JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior)
{
    return new JsonResult
    {
        Data = data,
        ContentType = contentType,
        ContentEncoding = contentEncoding,
        JsonRequestBehavior = behavior
    };
}传递contentType和contentEncoding对象的位置null。因此,从根本上讲return Json(object),调用controller等同于call return new JsonResult { Data = object, JsonRequestBehavior = sonRequestBehavior.DenyGet }。您可以使用第二种形式并进行参数化JsonResult。
那么,当您设置MaxJsonLength属性(默认情况下为空)时会发生什么?它传递给JavaScriptSerializer.MaxJsonLength属性,然后调用JavaScriptSerializer.Serialize方法:
JavaScriptSerializer serializer = new JavaScriptSerializer();
if (MaxJsonLength.HasValue)
{
    serializer.MaxJsonLength = MaxJsonLength.Value;
}
if (RecursionLimit.HasValue)
{
    serializer.RecursionLimit = RecursionLimit.Value;
}
response.Write(serializer.Serialize(Data));如果此maxJsonLength值是一个int,那么它的int 32bit / 64bit / 16bit是多少....我只是想确定我可以设置为maxJsonLength的最大值是多少
<scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483647">
            </jsonSerialization>
        </webServices>
    </scripting>您不需要使用web.config。您可以在传递列表的catch值期间使用short属性,例如,声明一个模型,例如
public class BookModel
    {
        public decimal id { get; set; }  // 1 
        public string BN { get; set; } // 2 Book Name
        public string BC { get; set; } // 3 Bar Code Number
        public string BE { get; set; } // 4 Edition Name
        public string BAL { get; set; } // 5 Academic Level
        public string BCAT { get; set; } // 6 Category
}在这里我使用简短的比例,例如BC =条形码BE =书籍版本,依此类推