在android中解析json数据时获取null值

时间:2016-10-14 17:22:35

标签: 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编写的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);

1 个答案:

答案 0 :(得分:0)

publisher似乎包含volumeInfo。尝试:

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