第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JSON 解析子項而不使用任何 lib

JSON 解析子項而不使用任何 lib

慕姐4208626 2023-11-10 15:27:52
我有這個 Google 圖書 JSON 文本要解析:   "volumeInfo": {    "title": "Year Book",    "subtitle": "The Annual Supplement to the World Book Encyclopedia : the 1989 World Book : a Review of the Events of 1988",    "authors": [     "World Book Encyclopedia"    ],    "publishedDate": "1989",    "industryIdentifiers": [     {      "type": "ISBN_10",      "identifier": "0716604892"     },     {      "type": "ISBN_13",      "identifier": "9780716604891"     }    ],    "readingModes": {     "text": false,     "image": false    },    "pageCount": 608,    "printType": "BOOK",    "categories": [     "Encyclopedias and dictionaries"    ],    "maturityRating": "NOT_MATURE",    "allowAnonLogging": false,    "contentVersion": "0.1.1.0.preview.0",    "panelizationSummary": {     "containsEpubBubbles": false,     "containsImageBubbles": false    },    "imageLinks": {     "smallThumbnail": "http://books.google.com/books/content?id=SDFIuwEACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api",     "thumbnail": "http://books.google.com/books/content?id=SDFIuwEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api"    },    "language": "en",    "previewLink": "http://books.google.it/books?id=SDFIuwEACAAJ&dq=isbn:0716604892&hl=&cd=2&source=gbs_api",    "infoLink": "http://books.google.it/books?id=SDFIuwEACAAJ&dq=isbn:0716604892&hl=&source=gbs_api",    "canonicalVolumeLink": "https://books.google.com/books/about/Year_Book.html?hl=&id=SDFIuwEACAAJ"   }深入地說,我需要抓住這一點: "industryIdentifiers": [     {      "type": "ISBN_10",      "identifier": "0716604892"     },     {      "type": "ISBN_13",      "identifier": "9780716604891"     }    ]
查看完整描述

3 回答

?
一只名叫tom的貓

TA貢獻1906條經(jīng)驗 獲得超3個贊

industryIdentifiers是一個對象數(shù)組,因此您首先調(diào)用getJSONArray(String name)以獲取數(shù)組,然后調(diào)用getJSONObject(int index)以獲取對象。

你的代碼應該是:

JSONArray industryIdentifiers = volumeInfo.getJSONArray("industryIdentifiers");

if (industryIdentifiers.length() == 1) {

? ? JSONObject obj = industryIdentifiers.getJSONObject(0);

? ? ISBN = obj.getString("type") + ": " + obj.getString("identifier");

} else if (industryIdentifiers.length() == 2) {

? ? JSONObject obj1 = industryIdentifiers.getJSONObject(0);

? ? JSONObject obj2 = industryIdentifiers.getJSONObject(1);

? ? ISBN = obj1.getString("type") + ": " + obj1.getString("identifier") + " - "

? ? ? ? ?+ obj2.getString("type") + ": " + obj2.getString("identifier");

}


查看完整回答
反對 回復 2023-11-10
?
精慕HU

TA貢獻1845條經(jīng)驗 獲得超8個贊

合并兩個答案,滿足我的需求的完美工作解決方案:


//ISBN

String ISBN = "";

     if(volumeInfo.toString().contains("industryIdentifiers")) {

     JSONArray industryIdentifiers = volumeInfo.getJSONArray("industryIdentifiers");

         if (industryIdentifiers.length() > 0) {

            for(int counter = 0; counter < industryIdentifiers.length(); counter++){

            JSONObject obj = industryIdentifiers.getJSONObject(counter);

            ISBN = ISBN + obj.getString("type") + ": " + obj.getString("identifier") + " ";

         }

     }

}

else{ISBN = "null";}


查看完整回答
反對 回復 2023-11-10
?
狐的傳說

TA貢獻1804條經(jīng)驗 獲得超3個贊

這是我將采取的方法:


if(volumeInfo.toString().contains("industryIdentifiers")) {

   JSONArray industryIdentifiers = volumeInfo.getJSONArray("industryIdentifiers");

if(industryIdentifiers != null && industryIdentifiers.length > 0) {

  for(int i = 0; i < industryIdentifiers.length; i++) {

   JSONObject industryIdentifier = industryIdentifiers.getJSONObject(i);

// Get the ISBN info from the current identifier and concatenate it to your ISBN string

}


} else {

  ISBN = "null";

}


查看完整回答
反對 回復 2023-11-10
  • 3 回答
  • 0 關(guān)注
  • 210 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號