如何加快使用JSON从服务器数据的获取? [英] How to speed up fetching of data from server using JSON?

查看:191
本文介绍了如何加快使用JSON从服务器数据的获取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个从断绝Android中使用JSON获取数据的应用程序。有喜欢的3000条记录是获取和加载似乎相当缓慢。在code,以获取数据如下 -

I am building an app that is fetching data from sever using JSON in android. There are like 3000 records that are fetched and the loading seems rather slow. The code to fetch data is as follows -

public static String executeHttpGet(String url) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = getHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI(url));
            HttpResponse response = client.execute(request);
//          in = new BufferedReader(new InputStreamReader(response.getEntity()
//                  .getContent()));
            in = new BufferedReader(new InputStreamReader(response.getEntity()
                    .getContent(), "UTF-8"));
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");

            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }

            in.close();

            String result = sb.toString();

            return result;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    Log.e("log_tag", "Error converting result " + e.toString());
                    e.printStackTrace();
                }
            }
        }

有没有什么可以做,以加快取?先谢谢了。

Is there anything that can be done to speed up the fetching? Thanks in advance.

推荐答案

见下图: -

有关快速反应,你必须使用改造。

For quick response you have to use retrofit.

http://instructure.github.io/blog /十二分之二千〇一十三/ 09 /抽射-VS-改造/

这篇关于如何加快使用JSON从服务器数据的获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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