Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.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
Javascript 字符串超过maxJsonLength,长度小于250kb_Javascript_C#_Jquery_Javascriptserializer_Pagemethods - Fatal编程技术网

Javascript 字符串超过maxJsonLength,长度小于250kb

Javascript 字符串超过maxJsonLength,长度小于250kb,javascript,c#,jquery,javascriptserializer,pagemethods,Javascript,C#,Jquery,Javascriptserializer,Pagemethods,我将实体与ajax一起使用。我想要用JavaScript创建的网格中的实体框架提供的完整表。我当前发送的表不到140行。如果我的表中只有50行,那么我的代码就可以正常工作。如果我遇到以下错误: {"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJ

我将实体与ajax一起使用。我想要用JavaScript创建的网格中的实体框架提供的完整表。我当前发送的表不到140行。如果我的表中只有50行,那么我的代码就可以正常工作。如果我遇到以下错误:

{"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":"   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj)\r\n   at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
在我的网络统计中,我的XMLHttpRequest在响应体中出现了500个错误,错误如上所示。如果我将行数限制在50行,我可以让页面正常工作,并且可以在响应正文中看到我的数据。以下代码是将数据从实体发送到javascript所需的全部代码。 JavaScript:

$(function() {
    $.ajax({
        url: "EditFeedApac.aspx/GetApacData",
        type: "POST",
        contentType: "application/json",
        success: function (result) {
            console.log(result.d);
        },
        error: showError
    });
});
C#

现在MaxJsonLength可以变成4MB大小,只是为了减少限制。 使用此属性集,我仍然会收到相同的序列化错误? 我做错了什么?
如何将数据发送到JavaScript?

尝试通过以下方式更改配置文件:

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

被覆盖。

当使用ScriptMethod属性和静态方法(禁止使用非静态序列化方法)使数据可供JavaScript使用时,此响应特别有用。非常感谢。
var serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
string test = serializer.Serialize(newData);
return test;
<configuration> 
  <system.web.extensions>
    <scripting>
       <webServices>
           <jsonSerialization maxJsonLength="50000000"/>
       </webServices>
    </scripting>
  </system.web.extensions>
</configuration> 
serializer.MaxJsonLength = Int32.MaxValue;