Alamofire.request(videosUrl!).responseJSON { response in
if response.result.value != nil {
let json = response.data
do {
let readableJSON = try JSONSerialization.jsonObject(with: json!, options: .mutableContainers) as? JSONStandard
if let items = readableJSON {
for i in 0..<items.count {
let item = items[i] <<< ERROR HERE
...REST OF CODE HERE
}
}
} catch {
print(error)
}
}
}
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.
The error happens, because subscript method of
Dictionary
(which is yoursJSONStandard
) requires:1)
String
as a key parameter, but you passingi
which hasInt
type. And according to the example your code is based on you probably should replacewith
In this case
items
becomes anArray
which usesInt
index in subscript method.2) or because
Dictionary
is also a collection with index typeDictionaryIndex<Key, Value>
subscript also can expectDictionaryIndex<String, AnyObject>
. In your case you can replacewith
or even with
The solution you chose depends on the structure of your JSON