Google Book APIから以下のようにレスポンス(①)が来るので以下のように構造体(②)を作りました。
①
JSON
1{ 2 "kind": "books#volumes", 3 "totalItems": 1, 4 "items": [ 5 { 6 "kind": "books#volume", 7 "id": "xMMeNwAACAAJ", 8 "etag": "M8bNz6/uLH4", 9 "selfLink": "https://www.googleapis.com/books/v1/volumes/xMMeNwAACAAJ", 10 "volumeInfo": { 11 "title": "カラフル", 12 "authors": [ 13 "森絵都" 14 ], 15 "publishedDate": "2007-09", 16 "description": "生前の罪により、輪廻のサイクルから外されたぼくの魂。だが天使業界の抽選にあたり、再挑戦のチャンスを得た。自殺を図った少年、真の体にホームステイし、自分の罪を思い出さなければならないのだ。真として過ごすうち、ぼくは人の欠点や美点が見えてくるようになるのだが...。不朽の名作ついに登場。", 17 "industryIdentifiers": [ 18 { 19 "type": "ISBN_10", 20 "identifier": "4167741016" 21 }, 22 { 23 "type": "ISBN_13", 24 "identifier": "9784167741013" 25 } 26 ], 27 "readingModes": { 28 "text": false, 29 "image": false 30 }, 31 "pageCount": 259, 32 "printType": "BOOK", 33 "categories": [ 34 "Fantasy fiction" 35 ], 36 "averageRating": 3.5, 37 "ratingsCount": 27, 38 "maturityRating": "NOT_MATURE", 39 "allowAnonLogging": false, 40 "contentVersion": "preview-1.0.0", 41 "imageLinks": { 42 "smallThumbnail": "http://books.google.com/books/content?id=xMMeNwAACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api", 43 "thumbnail": "http://books.google.com/books/content?id=xMMeNwAACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api" 44 }, 45 "language": "ja", 46 "previewLink": "http://books.google.co.jp/books?id=xMMeNwAACAAJ&dq=isbn:9784167741013&hl=&cd=1&source=gbs_api", 47 "infoLink": "http://books.google.co.jp/books?id=xMMeNwAACAAJ&dq=isbn:9784167741013&hl=&source=gbs_api", 48 "canonicalVolumeLink": "https://books.google.com/books/about/%E3%82%AB%E3%83%A9%E3%83%95%E3%83%AB.html?hl=&id=xMMeNwAACAAJ" 49 }, 50 "saleInfo": { 51 "country": "JP", 52 "saleability": "NOT_FOR_SALE", 53 "isEbook": false 54 }, 55 "accessInfo": { 56 "country": "JP", 57 "viewability": "NO_PAGES", 58 "embeddable": false, 59 "publicDomain": false, 60 "textToSpeechPermission": "ALLOWED", 61 "epub": { 62 "isAvailable": false 63 }, 64 "pdf": { 65 "isAvailable": false 66 }, 67 "webReaderLink": "http://play.google.com/books/reader?id=xMMeNwAACAAJ&hl=&printsec=frontcover&source=gbs_api", 68 "accessViewStatus": "NONE", 69 "quoteSharingAllowed": false 70 }, 71 "searchInfo": { 72 "textSnippet": "生前の罪により、輪廻のサイクルから外されたぼくの魂。だが天使業界の抽選にあたり、再挑戦のチャンスを得た。自殺を図った少年、真の体にホームステイし、自分の罪を思い ..." 73 } 74 } 75 ] 76}
②
JSON
1type GoogleBook struct { 2 Kind string `json:"kind"` 3 TotalItems int `json:"totalItems"` 4 Items []struct { 5 Kind string `json:"kind"` 6 ID string `json:"id"` 7 Etag string `json:"etag"` 8 SelfLink string `json:"selfLink"` 9 VolumeInfo struct { 10 Title string `json:"title"` 11 Authors []string `json:"authors"` 12 PublishedDate string `json:"publishedDate"` 13 Description string `json:"description"` 14 IndustryIdentifiers []struct { 15 Type string `json:"type"` 16 Identifier string `json:"identifier"` 17 } `json:"industryIdentifiers"` 18 ReadingModes struct { 19 Text bool `json:"text"` 20 Image bool `json:"image"` 21 } `json:"readingModes"` 22 PageCount int `json:"pageCount"` 23 PrintType string `json:"printType"` 24 Categories []string `json:"categories"` 25 AverageRating float64 `json:"averageRating"` 26 RatingsCount int `json:"ratingsCount"` 27 MaturityRating string `json:"maturityRating"` 28 AllowAnonLogging bool `json:"allowAnonLogging"` 29 ContentVersion string `json:"contentVersion"` 30 ImageLinks struct { 31 SmallThumbnail string `json:"smallThumbnail"` 32 Thumbnail string `json:"thumbnail"` 33 } `json:"imageLinks"` 34 Language string `json:"language"` 35 PreviewLink string `json:"previewLink"` 36 InfoLink string `json:"infoLink"` 37 CanonicalVolumeLink string `json:"canonicalVolumeLink"` 38 } `json:"volumeInfo"` 39 SaleInfo struct { 40 Country string `json:"country"` 41 Saleability string `json:"saleability"` 42 IsEbook bool `json:"isEbook"` 43 } `json:"saleInfo"` 44 AccessInfo struct { 45 Country string `json:"country"` 46 Viewability string `json:"viewability"` 47 Embeddable bool `json:"embeddable"` 48 PublicDomain bool `json:"publicDomain"` 49 TextToSpeechPermission string `json:"textToSpeechPermission"` 50 Epub struct { 51 IsAvailable bool `json:"isAvailable"` 52 } `json:"epub"` 53 Pdf struct { 54 IsAvailable bool `json:"isAvailable"` 55 } `json:"pdf"` 56 WebReaderLink string `json:"webReaderLink"` 57 AccessViewStatus string `json:"accessViewStatus"` 58 QuoteSharingAllowed bool `json:"quoteSharingAllowed"` 59 } `json:"accessInfo"` 60 SearchInfo struct { 61 TextSnippet string `json:"textSnippet"` 62 } `json:"searchInfo"` 63 } `json:"items"` 64} 65
ISBNがはいっている③がある時と無い時があり、それのエラー処理の仕方がわかりません。
③
JSON
1IndustryIdentifiers []struct { 2 Type string `json:"type"` 3 Identifier string `json:"identifier"` 4 } `json:"industryIdentifiers"` 5 6⬇ 7 8"industryIdentifiers": [ 9 { 10 "type": "ISBN_10", 11 "identifier": "4167741016" 12 }, 13 { 14 "type": "ISBN_13", 15 "identifier": "9784167741013" 16 } 17 ],
③がない場合は、ISBN_10, ISBN_13は空であるようにしたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。