想要从此链接中提取数据 - https://www.googleapis.com/books/v1/volumes?q=android&maxResults=16
这是我提取标题和作者的代码,但我可以获得标题而不是作者。
JSONObject root = new JSONObject(bookJSON);
JSONArray bookArray = root.getJSONArray("items");
String autho = " ";
for (int i = 0; i < bookArray.length(); i++) {
JSONObject currentBook = bookArray.getJSONObject(i);
JSONObject volumeInfo = currentBook.getJSONObject("volumeInfo");
String title = volumeInfo.getString("title");
Log.i("booktitle",title);
JSONArray auth = volumeInfo.getJSONArray("authors");
for (int j = 0; j > auth.length(); j++) {
autho = auth.getString(j);
Log.i("authorname",autho);
}
}
答案 0 :(得分:0)
JSONArray auth = volumeInfo.getJSONArray("authors");
int len = auth.length();
for (int j = 0; j < len; j++) {
autho = auth.get(j).toString();
Log.i("authorname",autho);
}
您需要获取JSONArray
的每个索引元素,然后将其转换为String
。