2017-05-04 22 views
1

我想打一個api,我會得到很多值並想在列表視圖中顯示。從json中載入數千的值

顯示listview上的數據我可以做到這一點,但問題是我無法在我的Android應用程序中加載完整的數據。當我點擊api的迴應時,只有少數數據可以顯示,或者只顯示幾行顯示,但數據顯示爲數千行。

當我從網頁瀏覽器中打開api時,它顯示所有的數據,但是當我在按鈕命中我的android應用程序上使用它時,只會提供有限的數據。

感謝提前:)

代碼按鈕我得到的數據打

try { 
       String url = "my url"; 

      HttpHandler sh = new HttpHandler(); 

       // Making a request to url and getting response 
       String jsonStr = sh.makeServiceCall(url); 


       Log.e("Response from url:", "" + jsonStr); 

     } 

++++++++++++++++++++++ +++
的HttpHandler類代碼

public class HttpHandler { 

private static final String TAG = HttpHandler.class.getSimpleName(); 

public HttpHandler() { 
} 

public String makeServiceCall(String reqUrl) { 
    String response = null; 
    try { 
     URL url = new URL(reqUrl); 
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
     conn.setRequestMethod("POST"); 
     // read the response 
     InputStream in = new BufferedInputStream(conn.getInputStream()); 
     response = convertStreamToString(in); 
    } catch (MalformedURLException e) { 
     Log.e(TAG, "MalformedURLException: " + e.getMessage()); 
    } catch (ProtocolException e) { 
     Log.e(TAG, "ProtocolException: " + e.getMessage()); 
    } catch (IOException e) { 
     Log.e(TAG, "IOException: " + e.getMessage()); 
    } catch (Exception e) { 
     Log.e(TAG, "Exception: " + e.getMessage()); 
    } 
    return response; 
} 

private String convertStreamToString(InputStream is) { 
    BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
    StringBuilder sb = new StringBuilder(); 

    String line; 
    try { 
     while ((line = reader.readLine()) != null) { 
      sb.append(line).append('\n'); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } finally { 
     try { 
      is.close(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
    return sb.toString(); 
} 

}

+0

你怎麼知道它給您的設備上有限的數據消息?你打印了回覆的長度嗎?因爲調試器在數據太長時會切斷數據 – Denny

+0

會放入您的json解析代碼。 –

+0

@Denny我有記錄響應的值。它僅顯示40-50行數據。 –

回答