簡體   English   中英

在Android中解析JSON數據時獲取空值

[英]getting null value while parsing json data in android

我試圖解析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編寫的Java代碼

 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);

似乎publisher者包含在volumeInfo 嘗試:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM