[英]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.