質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

1回答

1163閲覧

JSONのパースエラー

gtime

総合スコア51

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2017/06/08 14:50

json

1{ 2 "contributors_enabled" = 0; 3 "created_at" = "Sun Mar 11 18:05:57 +0000 2007"; 4 "default_profile" = 0; 5 "default_profile_image" = 0; 6 description = "Coder, photographer, relentless traveler, beer judge, Russian"; 7 entities = { 8 description = { 9 urls = ( 10 ); 11 }; 12 url = { 13 urls = ( 14 { 15 "display_url" = "zmievski.org"; 16 "expanded_url" = "http://zmievski.org/"; 17 indices = ( 18 0, 19 23 20 ); 21 url = "https://t.co/GwZtWimRHf"; 22 } 23 ); 24 }; 25 }; 26 "favourites_count" = 668; 27 "follow_request_sent" = 0; 28 "followers_count" = 151061; 29 following = 0; 30 "friends_count" = 285; 31 "geo_enabled" = 0; 32 "has_extended_profile" = 0; 33 id = 940631; 34 "id_str" = 940631; 35 "is_translation_enabled" = 0; 36 "is_translator" = 0; 37 lang = en; 38 "listed_count" = 1920; 39 location = "San Francisco, CA"; 40 name = "Andrei Zmievski"; 41 notifications = 0; 42 "profile_background_color" = 170F00; 43 "profile_background_image_url" = "http://pbs.twimg.com/profile_background_images/2909595/AZ-twitter.gif"; 44 "profile_background_image_url_https" = "https://pbs.twimg.com/profile_background_images/2909595/AZ-twitter.gif"; 45 "profile_background_tile" = 0; 46 "profile_image_url" = "http://pbs.twimg.com/profile_images/448301181324894208/vqY_gIaL_normal.jpeg"; 47 "profile_image_url_https" = "https://pbs.twimg.com/profile_images/448301181324894208/vqY_gIaL_normal.jpeg"; 48 "profile_link_color" = A04521; 49 "profile_location" = "<null>"; 50 "profile_sidebar_border_color" = E6AA51; 51 "profile_sidebar_fill_color" = E6AA51; 52 "profile_text_color" = 170F00; 53 "profile_use_background_image" = 1; 54 protected = 0; 55 "screen_name" = a; 56 status = { 57 contributors = "<null>"; 58 coordinates = "<null>"; 59 "created_at" = "Thu Jun 08 08:24:33 +0000 2017"; 60 entities = { 61 hashtags = ( 62 ); 63 media = ( 64 { 65 "display_url" = "pic.twitter.com/oPU2oPeUkX"; 66 "expanded_url" = "https://twitter.com/a/status/872731058852286464/photo/1"; 67 id = 872731053735149569; 68 "id_str" = 872731053735149569; 69 indices = ( 70 83, 71 106 72 ); 73 "media_url" = "http://pbs.twimg.com/media/DByQRPpWAAEojJw.jpg"; 74 "media_url_https" = "https://pbs.twimg.com/media/DByQRPpWAAEojJw.jpg"; 75 sizes = { 76 large = { 77 h = 768; 78 resize = fit; 79 w = 1024; 80 }; 81 medium = { 82 h = 768; 83 resize = fit; 84 w = 1024; 85 }; 86 small = { 87 h = 510; 88 resize = fit; 89 w = 680; 90 }; 91 thumb = { 92 h = 150; 93 resize = crop; 94 w = 150; 95 }; 96 }; 97 type = photo; 98 url = "https://t.co/oPU2oPeUkX"; 99 } 100 ); 101 symbols = ( 102 ); 103 urls = ( 104 ); 105 "user_mentions" = ( 106 ); 107 }; 108 "extended_entities" = { 109 media = ( 110 { 111 "display_url" = "pic.twitter.com/oPU2oPeUkX"; 112 "expanded_url" = "https://twitter.com/a/status/872731058852286464/photo/1"; 113 id = 872731053735149569; 114 "id_str" = 872731053735149569; 115 indices = ( 116 83, 117 106 118 ); 119 "media_url" = "http://pbs.twimg.com/media/DByQRPpWAAEojJw.jpg"; 120 "media_url_https" = "https://pbs.twimg.com/media/DByQRPpWAAEojJw.jpg"; 121 sizes = { 122 large = { 123 h = 768; 124 resize = fit; 125 w = 1024; 126 }; 127 medium = { 128 h = 768; 129 resize = fit; 130 w = 1024; 131 }; 132 small = { 133 h = 510; 134 resize = fit; 135 w = 680; 136 }; 137 thumb = { 138 h = 150; 139 resize = crop; 140 w = 150; 141 }; 142 }; 143 type = photo; 144 url = "https://t.co/oPU2oPeUkX"; 145 } 146 ); 147 }; 148 "favorite_count" = 4; 149 favorited = 0; 150 geo = "<null>"; 151 id = 872731058852286464; 152 "id_str" = 872731058852286464; 153 "in_reply_to_screen_name" = "<null>"; 154 "in_reply_to_status_id" = "<null>"; 155 "in_reply_to_status_id_str" = "<null>"; 156 "in_reply_to_user_id" = "<null>"; 157 "in_reply_to_user_id_str" = "<null>"; 158 "is_quote_status" = 0; 159 lang = en; 160 place = "<null>"; 161 "possibly_sensitive" = 0; 162 "retweet_count" = 1; 163 retweeted = 0; 164 source = "<a href=\"http://tapbots.com/tweetbot\" rel=\"nofollow\">Tweetbot for i\U039fS</a>"; 165 text = "What an abomination. Ingredients contain \"ethanol, juniper flavor\" among the rest. https://t.co/oPU2oPeUkX"; 166 truncated = 0; 167 }; 168 "statuses_count" = 14271; 169 "time_zone" = "Pacific Time (US & Canada)"; 170 "translator_type" = regular; 171 url = "https://t.co/GwZtWimRHf"; 172 "utc_offset" = "-25200"; 173 verified = 0; 174}

このJSONのverified部分をパースするコードを書きましたが

swift

1 2let foo: Int = json["verified"] as! Int 3 4 if foo == 0 { 5 print("aaaaa") 6 } 7

イメージ説明

このようなエラーが出てしまいます
どのようにすれば正しく実行できるのでしょうか

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fuzzball

2017/06/09 00:44

JSONではないようですが?
fuzzball

2017/06/09 01:43

print(type(of: json)) の出力を教えて下さい。
guest

回答1

0

JSONの形式についてご参考ください。
【参考URL】
http://dev.classmethod.jp/etc/concrete-example-of-json/

貼っていただいたJSONにはイコールなど余計な文字が入っており、それでエラーが出ているように思われます。

投稿2017/06/09 00:50

s.t.

総合スコア2021

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問