JavaScriptSerializer.MaxJsonLength超标。什么是处理这个最好的做法? [英] JavaScriptSerializer.MaxJsonLength exceeded. What's the best practice for handling this?

查看:448
本文介绍了JavaScriptSerializer.MaxJsonLength超标。什么是处理这个最好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的amound数据我发送到使用jQuery的$。阿贾克斯()函数的客户端。我打电话返回JSON数据的ASP.NET Web服务的方法。一切是伟大的大多数搜索,但当我有一个大的数据集返回我遇到的的JavaScriptSerializer MaxJsonLength财产问题。什么是处理这个最好的做法?我不想只是任意设置最大长度。我可以设置MaxJsonLength在Web服务,如果返回的数据比目前的最高大,或者我应该重新编写和发送下行数据卡盘的客户端?

下面是从Web服务相关的片段:

 词典<字符串对象> jsonValuePairs =新词典<字符串对象>();
//一些数据添加到字典...
返回System.Web.Script.Serialization.JavaScriptSerializer.Serialize(jsonValuePairs);


解决方案

要设置从客户端脚本呼吁Web方法的最大长度的唯一方法是通过web.config文件(如下图)。
什么是设置此您的问题?
我会做这在多个XHR每次调用流数据的部分。

 < System.Web.Extensions程序>
  <脚本>
      <&Web服务GT;
        < jsonSerialization maxJsonLength =500000>
        < / jsonSerialization>
      < / WebServices的>
  < /脚本>
< /system.web.extensions>

更新:默认大小为2097152相当于4 MB的Uni code字符串数据。你真的要发送大量的数据返回给客户端?如果是这样哎哟,你需要的概率来看看应用程序设计为用户的体验将是缓慢和繁琐。

I've got a large amound of data I'm sending down to the client using jQuery's $.ajax() function. I'm calling a method in a ASP.NET web service that returns the JSON data. Everything is great for most searches, but when I've got a large data set to return I run into a issue with the JavaScriptSerializer MaxJsonLength property. What's the best practice for handling this? I don't want to just arbitrarily set a max length. Can I set the MaxJsonLength in the web service if the data being returned is larger than the current max or should I re-write and send down chucks of data to the client?

Here's the relevant snippet from the web service:

Dictionary<string, object> jsonValuePairs = new Dictionary<string, object>();
//add some data to the dictionary...
return System.Web.Script.Serialization.JavaScriptSerializer.Serialize(jsonValuePairs);

解决方案

The only way to set the maximum length for web methods that are called from client script is through the web.config file (below). What is your issue with setting this? I would do this every time over multiple xhr calls to stream parts of the data.

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

UPDATE: The default size is 2097152 which is equivalent to 4 MB of Unicode string data. Are you really going to send that much data back to the client? If so ouch and you prob need to look at the app design as the user experience will be slow and cumbersome.

这篇关于JavaScriptSerializer.MaxJsonLength超标。什么是处理这个最好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆