###前提・実現したいこと
swiftでQiitaのAPIクライアントアプリを作っています。
勉強を初めて数週間の者です。
(参考:QiitaAPIドキュメント
APIまわりの処理がイマイチわかっていません。
json
1[ 2 { 3 "body": "aaa", 4 "id": "bbb", 5 "private": false, 6 "rendered_body": "ccc", 7 "coediting": false, 8 "created_at": "2017-03-03T00:28:43+09:00", 9 "tags": [ 10 { 11 "name": "Swift", 12 "versions": [] 13 } 14 ], 15 "url": "http://example.com/", 16 "title": "sample code", 17 "group": null, 18 "updated_at": "2017-03-03T00:28:43+09:00", 19 "user": { 20 "description": "こんにちは。", 21 "followers_count": 1, 22 "id": "xxxxxxx", 23 "facebook_id": "", 24 "permanent_id": 1234, 25 "github_login_name": "xxxxxx", 26 "twitter_screen_name": null, 27 "followees_count": 1, 28 "website_url": "", 29 "linkedin_id": "", 30 "profile_image_url": "https://images/1234567", 31 "location": "", 32 "items_count": 2, 33 "name": "", 34 "organization": "" 35 } 36 }, 37 { 38 // 以下略 39 } 40]
このようなjsonがあったときに、
swift
1var items: [[String: String?]] = [] 2 json.forEach { (_, json) in 3 let item: [String: String?] = [ 4 "url": json["url"].string, 5 "title": json["title"].string, 6 "userId": json["user"]["id"].string, 7 "tagsName": json["tags"]["name"].string 8 ] 9 items.append(item) 10 } 11
このように"url"、"title"、"userId"はとることができたのですが、
"tags"の中のものがとれません。
あたまがこんがらがってきました。
優しく教えて頂けたらと思います。
回答1件
あなたの回答
tips
プレビュー