【发布时间】:2021-12-04 00:04:39
【问题描述】:
我是 JSON 的新手,不知道为什么会出现这个问题,所以我来了。我有一个公开共享的 Google Drive 文件夹 (https://drive.google.com/drive/folders/1RpFcoEWYsRt2MX7FotKcLICqYq6l5MFY)。这是我用来获取条目的代码(用于测试 atm):
new Thread(() -> {
String sUrl = "https://www.googleapis.com/drive/v3/files?q=%271RpFcoEWYsRt2MX7FotKcLICqYq6l5MFY%27+in+parents&key=myKey";
try {
URL url = new URL(sUrl);
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
JsonParser jp = new JsonParser();
JsonElement root = jp.parse(new InputStreamReader((InputStream) urlConnection.getContent()));
JsonObject rootObj = root.getAsJsonObject();
JsonArray files = rootObj.get("files").getAsJsonArray();
for (JsonElement file : files) {
String n = file.getAsJsonObject().get("name").getAsString();
Log.e("amt", counter.getAndIncrement() + "");
//if (n.toLowerCase().contains(name.toLowerCase())) ret.add(n);
}
((HttpsURLConnection) urlConnection).disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}).start();
此代码在控制台中打印数字 0-99,始终在 99 处停止,尽管文件夹中的文件比这更多。如果有人知道为什么会发生这种情况,请告诉我。也欢迎其他方法!
【问题讨论】:
标签: java android json google-drive-api