Swift3で、jsonから読み込んだNSArrayの中身をfor inループでパースしたいと考えているのですが、添字をつけるだけではデータが取得できないことを知りました。
print(String(describing: type(of: items))) for item in items as! NSArray{ print(String(describing: type(of: item))) print(item) }
このようなソースでは
__NSCFArray __NSCFDictionary { id = s01; "name," = ""; "image" = "i01.jpg"; "original_file" = "i01.jpg"; x = "1041.1"; y = "874.1"; height = 1920; width= 1080; } itemsには__NSCFDictionaryが入っています。 __NSCFDictionary { id = s02; "name," = "second"; "image" = "i02.jpg"; "original_file" = "i02.jpg"; ・ ・ ・
のようにデータが取得できているのですが、ループ内で
print(item["scene_item_no"] as String) print(String(item["scene_item_no"])) print((item as AnyObject).scene_item_no)
このように添え字をつけたりドットシンタックス指定しても
Type 'NSFastEnumeration Iterator.Element' (aka ''any) has no subscript members
とエラー表示が出てビルドすることができません。
添字の指定方法をご存じの方はいらっしゃいませんでしょうか。
ご教示お願い致します。
環境
macos Sierra
xcode 8.1
swift 3.0
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/24 02:31 編集
2016/11/24 03:25
2016/11/24 03:52