Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WebMethod-JSON序列化错误_C#_Json_Serialization_.net 3.5_Webmethod - Fatal编程技术网

C# WebMethod-JSON序列化错误

C# WebMethod-JSON序列化错误,c#,json,serialization,.net-3.5,webmethod,C#,Json,Serialization,.net 3.5,Webmethod,我正在对aspx.cs页面中的后端WebMethod进行jQueryAjax调用。我在.NET JSON序列化中遇到错误。因此,我正在寻找修复错误或避免使用JSON(WebMethods的唯一返回格式)的方法: 使用JSON JavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过了maxJsonLength属性上设置的值 关联的StackTrace是: 位于System.Web.Script.Serialization.JavaScriptSerializer.Se

我正在对aspx.cs页面中的后端WebMethod进行jQueryAjax调用。我在.NET JSON序列化中遇到错误。因此,我正在寻找修复错误或避免使用JSON(WebMethods的唯一返回格式)的方法:

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

关联的StackTrace是:
位于System.Web.Script.Serialization.JavaScriptSerializer.Serialization(对象obj、StringBuilder输出、SerializationFormat SerializationFormat)\r\n位于System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext上下文、WebServiceMethodData、IDictionary的2个参数)\r\n位于System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMethodData methodData)

后端代码如下所示(注意:
result
实际上是110k左右的控件呈现为字符串):

而且我从来没有碰到过
catch
块,这对我来说表明这个问题超出了我的代码范围

我通过插入以下块找到了一个涉及更改web.config的修复程序,但它不起作用:

<system.web.extensions>
    <scripting>
       <webServices>
          <jsonSerialization maxJsonLength="123456"></jsonSerialization>
       </webServices>
    </scripting>
</system.web.extensions>

该项目是.NET3.5


谢谢你的任何想法和建议

必须在web.config中设置maxJsonLength属性的配置。为了允许IIS允许此配置,必须在
中包含以下



我假设您的意思是,当您说方法开头的断点“从未命中
catch
块”时,它从未命中。代码保持原样,我真诚地怀疑
返回“Hello World!”
是否可能引发异常。请尝试将
maxJsonLength
再增加一吨。大约110kb约为112640字节,与123456字节相差不远。也许额外的开销(或者“about”不太准确)正在突破限制。试着把它打到9999999,看看会发生什么。纠正断点没有问题。当我在返回结果时中断时,它会显示结果的值,没有任何问题。谢谢你的建议,Chris,但是使用Web.Config会抱怨无效,搜索返回的IIS错误会使修复程序看起来只是.NET 4.0。也要感谢L.B!但是由于项目限制,很难获得开源解决方案的批准。上面提到的IIS错误:
HTTP错误500.19-内部服务器错误由于页面的相关配置数据无效,无法访问请求的页面。
<system.web.extensions>
    <scripting>
       <webServices>
          <jsonSerialization maxJsonLength="123456"></jsonSerialization>
       </webServices>
    </scripting>
</system.web.extensions>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
      <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
      <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    </sectionGroup>
  </sectionGroup>
</sectionGroup>