我设计了jqgrid来显示数据,但在执行时我收到了错误;
“Message”:“使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了maxJsonLength属性上设置的值。”,“StackTrace”:“
当我用最少的数据执行网格时......
我甚至尝试通过以下方式更改web.conf:
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
但错误仍然相同.Below是我的web.conf文件..
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="MySql.Data, Version=5.0.9.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/></assemblies></compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
答案 0 :(得分:2)
我不知道这是否是您问题的解决方案。 尝试在代码后面设置maxJsonLength(动态):
public static string GetJSONString <T> (List<T> data)
{
JavaScriptSerializer serializer = new JavaScriptSerializer() { MaxJsonLength = Int32.MaxValue, RecursionLimit = 100 };
return serializer.Serialize(data);
}
创建对象时初始化MaxJsonLength属性。 如果此解决方案不起作用,我认为您应该分隔您的JSON字符串lenghth。 希望这有帮助。