如何使用JSON加速从服务器获取数据?

时间:2014-05-05 04:11:24

标签: android json

我正在构建一个使用Android中的JSON从服务器获取数据的应用程序。有大约3000个记录被提取,加载似乎相当慢。获取数据的代码如下 -

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();
                }
            }
        }

有什么办法可以加快取物速度吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

见下图: -

enter image description here

为了快速响应,您必须使用改造。

http://instructure.github.io/blog/2013/12/09/volley-vs-retrofit/

相关问题