2012-02-16 30 views
1

我想下载只从JSON页面顶部10个新的更新,,,从JSON页只获得第10个更新directy,不下载整个页面第一,然后选择从它

这下面的代码下载ALLDATA在页面第一然后我选择我想要的,,,但我需要它只从服务器下载最新的10个更新,而无需首先下载整个页面

所以得到的代码尽可能快,因为这个页面是巨大的, 谢谢提前

public String readFeed() { 
     StringBuilder builder = new StringBuilder(); 
     HttpClient client = new DefaultHttpClient(); 
     HttpGet httpGet = new HttpGet(
       "http://www.zigwheels.com/api/zigtvApi.php?method=data&module=News&section=News"); 
     try { 
      HttpResponse response = client.execute(httpGet); 
      StatusLine statusLine = response.getStatusLine(); 
      int statusCode = statusLine.getStatusCode(); 
      if (statusCode == 200) { 
       HttpEntity entity = response.getEntity(); 
       InputStream content = entity.getContent(); 
       BufferedReader reader = new BufferedReader(
         new InputStreamReader(content)); 

       String line; 
       while ((line = reader.readLine()) != null ) { 

        builder.append(line); 


       } 
      } else { 
       Log.e(GridViewExampleActivity.class.toString(), "Failed to download file"); 
      } 
     } catch (ClientProtocolException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return builder.toString(); 
    } 

回答

0

AFAIK,您需要在您的Web服务中进行更改,让您的Web开发人员为您提供另一个只包含前10个新更新的数据的url,然后在Android端提供上述代码。

+0

我认为有一种方法可以从Android获得它 – Ti7a 2012-02-16 10:37:07

+0

你将如何下载一半的响应? - 不可能 – MKJParekh 2012-02-16 10:42:26

+0

嗯如何使用Gson你试过了吗? – Ti7a 2012-02-16 10:50:19

0

您需要google-gson-stream。把它想象成一个SAX XML解析器

+0

你有教程吗? – Ti7a 2012-02-16 10:40:04

+0

http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/index.html – weakwire 2012-02-16 12:20:54

0

Soni是对的 - 应该有一种方法让web服务只给你前10个更新。该行

HttpResponse response = client.execute(httpGet); 

将不会返回,除非数据全部接收,所以任何加快装载过程的机会都应该在服务器端完成。也许一个额外的

&count=10

您的要求,该服务器可以解释。

相关问题