如何加快使用JSON从服务器数据的获取?服务器、数据、JSON

2023-09-06 08:30:45 作者:清梦

我建立一个从断绝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-改造/