JSON数据大小限制 [英] JSON data size limit
问题描述
Section-1 - Controller Class
< code $ public public JsonResult GetPlotData(Dictionary< string,List< ChartData>> dataPlot)
{
// dataPlot = D00213 - [[13245678000,49.9],[13245345000, 43.9] ... [n,n]]
// if dataPlot.Count< 87500这里抛出错误和ajax错误404未找到
返回Json(dataPlot,JsonRequestBehavior.AllowGet);
$ / code>
Section-2 - Ajax
$ .ajax(
{
url:'../Report/GetPlotData',
data:{fromDate :fromDate,toDate:toDate,item:items [i] .id},
type:POST,
dataType:json,
cache:false,
成功:函数(chartData){
alert('success'
},
错误:函数(xhr,ajaxOptions,thrownError)
{
调试器;
ShowDialogError(xhr,'Site Status Report');
}
});
您的web服务器将限制最大响应大小限制,您应该参考您选择的Web服务器上的文档,以了解如何最大限度地增加该限制,而不管它是什么设置为今天。
JsonResult类确实有一个属性(maxJsonLength),你也可以尝试改变
var jsonResult = Json(dataPlot,JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
返回jsonResult;
可能的配置更改
<结构>
< system.web.extensions>
<脚本>
< webServices>
< jsonSerialization maxJsonLength =1000000/>
< / webServices>
< /脚本>
< /system.web.extensions>
< / configuration>
最重要的是 - 您可能希望重新考虑您的电话以限制或以某种方式将响应分割为更易于管理的块因为默认响应限制相当大,并且可能需要很长时间才能返回(网络延迟)。一般来说,增加您的响应大小限制通常不是一个好主意。但这可能是您遇到的问题。
In HighChart I needs to plot a series of data against x and y axis. HighChart expects the data to be in json format. ie, [ [ x, y],[x, y]……[x, y] ]. Where x and y are time ( 1392345000 – Unix epoch format ) and value ( 49.322 ). So I am making an ajax call to get the data and on success I render the json returned data in highchart. In most of the time ie, if the count of data( [x,y] ) is below 87500 rows than Json returns the data from controller to view. But when the data exceeds 87500 the ajax error is called with 404, not found error. Is there any size restriction for json returned data.
Section-1 – Controller Class
public JsonResult GetPlotData(Dictionary<string, List<ChartData>> dataPlot)
{
// dataPlot = D00213 - [[13245678000,49.9],[13245345000,43.9]...[n,n]]
// if dataPlot.Count < 87500 here throwing error and in ajax error 404 Not found
return Json(dataPlot, JsonRequestBehavior.AllowGet);
}
Section-2 – Ajax
$.ajax(
{
url: '../Report/GetPlotData',
data: { "fromDate": fromDate, "toDate":toDate, "item": items[i].id },
type: "POST",
dataType: "json",
cache: false,
success: function(chartData) {
alert(‘success’
},
error: function(xhr, ajaxOptions, thrownError)
{
debugger;
ShowDialogError(xhr, 'Site Status Report');
}
});
You webserver will limit the maximum response size limit. You should refer to documentation on your web server of choice to see how best to increase that limit beyond whatever it is set to today.
The JsonResult class does have a property (maxJsonLength) you may also try changing
var jsonResult = Json(dataPlot, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
Possible configuration change
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="1000000" />
</webServices>
</scripting>
</system.web.extensions>
</configuration>
Most importantly - you may want to reconsider your call to limit or somehow partition the responses into more manageable chunks as a default response limit is fairly large and can take a long time to return (network latency)
Generally speaking it's usually not a good idea to increase your response size limit. But that is probably the problem you are experiencing.
这篇关于JSON数据大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!