2017-05-05 51 views
0

想从这个链接中提取数据 - https://www.googleapis.com/books/v1/volumes?q=android&maxResults=16JsonArray从JsonArray

这是我的代码中提取标题和作者,但我能拿到冠军,但不是作者。

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

什么是你的问题? – megalucio

回答

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

+0

谢谢@Devendra,但支架出现在屏幕上,作者姓名像这样[Greg nudelman]我想删除支架到没有作者姓名的节目 – mohammedragabmohammedborik

+0

完成。我已经更新了代码。请看看@mohammedragabmohammedborik –