从 json 加载数千个值
Load thousand of values from json
我想点击 api,我将在其中获得很多值并希望在列表视图中显示。
在列表视图上显示数据我可以做到,但问题是我无法在我的 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 class 代码
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();
}
}
似乎是调试器问题切断了太长的消息
有关更多信息,请参阅 Android - Set max length of logcat messages
我想点击 api,我将在其中获得很多值并希望在列表视图中显示。
在列表视图上显示数据我可以做到,但问题是我无法在我的 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 class 代码
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();
}
}
似乎是调试器问题切断了太长的消息
有关更多信息,请参阅 Android - Set max length of logcat messages