2016-10-14 54 views
1

我想解析android應用中的json數據我能夠獲得本書和作者的標題,但我無法解析發佈者我在發佈者處獲得空值在解析android中的json數據時獲得空值

"kind":"books#volumes", 
     "totalItems":997, 
     "items":[ 
      { 
      "kind":"books#volume", 
      "id":"g3hAdK1IBkYC", 
      "etag":"o+CdTUx3mkQ", 
      "selfLink":"https://www.googleapis.com/books/v1/volumes/g3hAdK1IBkYC", 
      "volumeInfo":{ 
       "title":"Professional Android 4 Application Development", 
       "authors":[ 
        "Reto Meier" 
       ], 
       "publisher":"John Wiley & Sons", 
       "publishedDate":"2012-04-05", 
} 

這裏是對JSON

JSONObject root = new JSONObject(jsonResponse); 
      JSONArray itemsArray = root.optJSONArray("items"); 
      for (int i=0;i<itemsArray.length();i++){ 

       JSONObject singleItem = itemsArray.getJSONObject(i); 


       JSONObject volumeInfo = singleItem.getJSONObject("volumeInfo"); 
       String title = volumeInfo.getString("title"); 
       Log.i("title_book",title); 

       String author = volumeInfo.getString("authors"); 
       Log.i("author_book",author); 
       String publisher = singleItem.getString("publisher"); 
       Log.i("publisher_book",publisher); 
+0

您的JSON是格式不正確,儘量格式化,你應該能夠穿越它 –

+1

什麼exactlyare你想要說什麼?我的json沒有在我寫的問題或java代碼中格式化 –

回答

0

編寫Java代碼看來,publishervolumeInfo遏制。嘗試:

String publisher = volumeInfo.getString("publisher");