1

我设计了 jqgrid 来显示数据,但在执行时出现错误;

"Message":"使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了 maxJsonLength 属性设置的值。","StackTrace":"

当我用最少的数据执行网格时,它运行...

我什至尝试通过以下方式更改 web.conf:

<scripting>
<webServices>
  <jsonSerialization maxJsonLength="50000000"/>
</webServices>

但错误保持不变..下面是我的 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>

4

1 回答 1

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 字符串长度。希望这有帮助。

于 2013-02-01T07:36:24.907 回答