【发布时间】:2017-07-29 13:36:34
【问题描述】:
我正在尝试从此 google 图书 api“https://www.googleapis.com/books/v1/volumes?q=android&maxResults=20”获取结果
Json解析的代码是
try {
JSONObject root = new JSONObject(booksJson);
JSONArray books = root.getJSONArray("items");
for (int i = 0; i < books.length(); i++) {
JSONObject book = books.getJSONObject(i);
JSONObject info = book.getJSONObject("volumeInfo");
String title = info.getString("title");
JSONArray authors = info.getJSONArray("authors");
String author = authors.getString(0);
JSONObject imageLinks = info.getJSONObject("imageLinks");
String imageLink = imageLinks.getString("smallThumbnail");
Book bookObject = new Book(author,title,imageLink);
booksList.add(bookObject);
Log.d(LOG_TAG + " Index :", String.valueOf(i) + " : " + String.valueOf(books.length()));
}
} catch (JSONException e) {
}
问题是当我在 Web 浏览器中检查时有 20 个结果,当我在 logcat 中记录 books.length() 时它也显示 20 个结果,但它会跳过一些书并显示更少的结果。请帮忙。
【问题讨论】:
-
你怎么能得出你得到较少结果的结论?
-
在 android 模拟器中运行应用程序时得到的结果较少
-
那它在真机上效果好吗?
-
真机还没试过
-
你说登录 books.length() 时会显示 20 个结果,那么问题是什么?