Ashish Choudhary Ashish Choudhary - 1 month ago 11
JSON Question

getting null value while parsing json data in android

i am trying to parse json data in android app i am able to get title of the book and author but i am not able to parse publisher i am getting null value at publisher

"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",
}


here is the java code written for 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);

Answer

It seems that the publisher is contained by volumeInfo. Try:

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