2017-05-05 2 views
0

에서 JsonArray이 링크에서 데이터를 추출 할 - https://www.googleapis.com/books/v1/volumes?q=android&maxResults=16JsonArray

이 제목과 저자를 추출하는 내 코드는하지만 난 제목하지만 저자를 얻을 수 있습니다.

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 –