[英]MaxJsonLength error in NewtonSoft JsonConvert.SerializeObject
I have a ASP.NET project, with some AJAX calling a webmethod, that would return JSON. 我有一个ASP.NET项目,其中一些AJAX调用了webmethod,它将返回JSON。
If the DataSet
has about 100 lines, there is no problem. 如果
DataSet
大约有100行,则没有问题。 But with 1000 lines, it launch the error: 但是,如果有1000行,它将引发错误:
Error during serialization or deserialization using JSON JavaScriptSerializer.
使用JSON JavaScriptSerializer进行序列化或反序列化时出错。 The size of the string exceeds the value set in the maxJsonLength property
字符串的大小超过在maxJsonLength属性中设置的值
[WebMethod(EnableSession = true)]
public static string PublicWebMethod()
{
DataSet ds = new DataSet(); // in the reality do a mountrous query
if (ds.Tables[0].Rows.Count > 0)
{
return JsonConvert.SerializeObject(clsUtil.ToArray(ds.Tables[0]));
}
else
{
return "false";
}
}
}
How can I solve this by setting a configuration in the method? 如何通过在方法中设置配置来解决此问题?
I don't want to change the web.config
我不想更改
web.config
I had the similar issue and took a while to figure out the problem and fix. 我遇到了类似的问题,花了一段时间找出问题并解决。 Please include the following code after
请在下面添加以下代码
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000" />
</webServices>
</scripting>
</system.web.extensions>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.