我也有一个typealias设置:
I also have a typealias set:
typealias JSONStandard = [String:AnyObject]我的问题是为什么我得到对成员下标的含糊引用错误?我要做的就是访问数组的正确部分。
My question is why am I getting the 'Ambiguous reference to member subscript' error? All I am trying to do is access the correct part of the array.
推荐答案发生错误,因为 Dictionary (这是您的 JSONStandard )需要:
The error happens, because subscript method of Dictionary (which is yours JSONStandard) requires:
1) String 作为关键参数,但是您传递的 i 具有 Int 类型。根据示例,您的代码所基于的示例可能应该替换
1) String as a key parameter, but you passing i which has Int type. And according to the example your code is based on you probably should replace
if let items = readableJSON { ... }with
if let tracks = readableJSON["tracks"] as? JSONStandard { if let items = tracks["items"] as? [JSONStandard] { ... } }在这种情况下,项变为 Array ,该数组使用 Int 索引
In this case items becomes an Array which uses Int index in subscript method.
2)或因为 Dictionary 也是索引类型为的集合DictionaryIndex<键,值> 下标也可以期望 DictionaryIndex< String,AnyObject> 。在您的情况下,您可以将i替换为
2) or because Dictionary is also a collection with index type DictionaryIndex<Key, Value> subscript also can expect DictionaryIndex<String, AnyObject>. In your case you can replace
for i in 0..<items.count {有
for i in items.indices {甚至连
for (_, item) in items {项目中的(_,项目)选择哪种取决于您的 JSON
The solution you chose depends on the structure of your JSON
更多推荐
对Alamofire中的成员下标的含糊不清的引用
发布评论