2011-08-10 48 views

回答

0

嘗試使用BufferedReader和StringBuilder(這就是我目前用於我的應用程序)。然後我使用String來創建一個JSONObject。下面是一些你可以使用模板代碼:

try{ 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpGet httpget = new HttpGet(//YOUR URL STRING HERE); 
    HttpResponse response; 
    response = httpclient.execute(httpget); 
    HttpEntity entity = response.getEntity(); 
    InputStream in = entity.getContent(); 

    BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 
    StringBuilder sb = new StringBuilder(); 

    String input = null; 
    try { 
     while ((input = reader.readLine()) != null) { 
        sb.append(input + "\n"); 
     } 
    } catch (IOException e) { 
      e.printStackTrace(); 
    } finally { 
     try { 
      in.close(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
    String enter = sb.toString(); 
     JSONObject obj = new JSONObject(enter); 

       //DO WHATEVER YOU WANT WITH THE JSONObject here 

     in.close(); 
} catch(MalformedURLException e){ 
    e.printStackTrace(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} catch (JSONException e){ 
    e.printStackTrace(); 
} 
+0

注意,這裏使用下org.json – Vinay

+0

感謝維奈簡單JSON庫,我不知道我應該做的。 – Archie

+0

沒有問題broski。 – Vinay