gpt4 book ai didi

android - 从 json 加载数千个值

转载 作者:行者123 更新时间:2023-11-29 19:15:10 24 4
gpt4 key购买 nike

我想点击一个 api,我将在其中获得很多值并希望在 ListView 中显示。

在 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();
}

最佳答案

似乎是调试器问题切断了太长的消息

参见 Android - Set max length of logcat messages更多

关于android - 从 json 加载数千个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43780829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com