【发布时间】:2017-02-24 05:12:15
【问题描述】:
我正在尝试在 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);
【问题讨论】:
-
你的json格式不好,试试格式化,应该可以遍历的
-
你到底想说什么?我的 json 未在问题或我编写的 java 代码中格式化