【问题标题】:How to speed up fetching of data from server using JSON?如何使用 JSON 加快从服务器获取数据的速度?
【发布时间】:2014-05-05 04:11:24
【问题描述】:

我正在构建一个应用程序,该应用程序在 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();
                }
            }
        }

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

【问题讨论】:

    标签: android json


    【解决方案1】:

    见下图:-

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

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

    【讨论】:

    • 你能帮我开始改造吗,因为网上的内容让我很困惑。假设我在 www.kurdshopping.net/apj/subcat.php 有一个 PHP 脚本,必须使用参数 id=15 的 get 方法调用它。如何使用改造调用脚本?
    猜你喜欢
    • 2013-05-03
    • 2021-12-14
    • 2016-10-13
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多