简体   繁体   English

获取大json数据结果asp.net MVC

[英]Getting Big json data result asp.net mvc

I am using asp.net mvc. 我正在使用asp.net mvc。 This Project is a map based Project. 该项目是基于地图的项目。 I have an action method that returns big json data. 我有一个返回大json数据的操作方法。

    public JsonResult MemberLocations()
    {
        var members = memberRepository.GetAll();

        var result = new { members };

        var jsonresult = Json(result, JsonRequestBehavior.AllowGet);
        jsonresult.MaxJsonLength = 500000000;

        return jsonresult;
    }

This method returns members locations. 此方法返回成员位置。

[{memberX:"132.45", memberY:"212.21"}, {memberX:"112.45", memberY:"113.11"},........]

The json data has 45.000 point (x,y) pairs. json数据具有45.000点(x,y)对。 I am getting this points an adding pin on the map. 我在地图上指出了这一点。 The query result is coming very late. 查询结果来得很晚。 (I am using javascript ajax request. ) (我正在使用javascript ajax请求。)

How can I solve the data getting mechanism. 如何解决数据获取机制。 Have you solved a problem like this? 您解决了这样的问题吗?

You need to profile this function for performance, which part of this taking more time. 您需要对此功能进行性能分析,其中的一部分需要花费更多时间。 Sending array of JSON object of size 45 would not take more time. 发送大小为45的JSON对象数组不会花费更多时间。 It seems it may be taking more time in getting the data "memberRepository.GetAll()". 似乎获取数据“ memberRepository.GetAll()”可能要花费更多时间。

First you should check if it is really the transfer of 45k points which slows down the application or if it is your data retrieval. 首先,您应该检查是否真的是45k点的传输降低了应用程序的速度,还是您的数据检索。 Just use stopwatch around the call of memberRepository.GetAll(); 只需在memberRepository.GetAll();的调用周围使用秒表memberRepository.GetAll(); and measure the time of the response in fiddler to evaluate how much % of the time it takes to retrieve the data... 并在提琴手中测量响应时间,以评估检索数据所花费的时间百分比。

Usually you should really not send so much data to the client. 通常,您实际上不应该向客户端发送太多数据。 It usually results in bad user experience, especially on slower devices (mobile...). 通常会导致不良的用户体验,尤其是在速度较慢的设备(移动设备)上。

Maybe you have to ask yourself why do you have to send 45k coordinates to the client? 也许您必须问自己,为什么必须向客户发送45k坐标?

Are you showing all the pins on the map at once? 您要一次在地图上显示所有图钉吗? Really? 真? If not, send only those which should be displayed for the zoom level/view port... 如果没有,则仅发送应在缩放级别/查看端口显示的内容...

If you still need to render that much data, use other techniques to render it, eg rendering tiles on the server. 如果仍然需要渲染那么多数据,请使用其他技术来渲染它,例如在服务器上渲染图块。

Another option for lots of LatLong coordinates is to encode the data, which will reduce the size. 许多LatLong坐标的另一种选择是对数据进行编码,这将减小大小。 This can be achieved with this google algorithm for example 例如,可以使用此Google算法实现目标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM