我正在創建一個應用程序,它使用Google API獲取有關Google圖書的獲取詳細信息。在JSON代碼中尋找路徑
從下面的JSON鏈接我想檢索有關作者和書名的數據。
https://www.googleapis.com/books/v1/volumes?q=android
我對這個問題的方法:
private Book extractFeatureFromJson(String bookJSON) {
try {
JSONObject baseJsonResponse = new JSONObject(bookJSON);
JSONArray items = baseJsonResponse.getJSONArray("items");
// If there are results in the features array
for(int i=0;i<10;i++)
{
JSONObject firstFeature = items.getJSONObject(i);
JSONObject volumeinfo=firstFeature.getJSONObject("volumeinfo");
String title=volumeinfo.getString("title");
JSONArray author= volumeinfo.getJSONArray("authors");
for(int j=0;j<author.length();j++)
{
JSONObject authorFeature=author.getJSONObject(j);
}
// Create a new {@link Event} object
return new Book(title,author);
}
} catch (JSONException e) {
Log.e(LOG_TAG, "Problem parsing the earthquake JSON results", e);
}
return null;
}
我對路徑的做法是錯誤的,我不能弄明白哪裏是錯誤的。
你可以把JSON響應? –
這裏是先生https://www.googleapis.com/books/v1/volumes?q=android –
'author.getJSONObject(j);'你認爲'authors'的內容是對象的是什麼? – njzk2