I'm new to using Alamofire and have encountered an issue. I'm able to run the following code to print out all the data from an API endpoint.
Alamofire.request("http://codewithchris.com/code/afsample.json").responseJSON { response in
if let JSON = response.result.value {
print(JSON)
}
}
The issue is that when I run this:
Alamofire.request("http://codewithchris.com/code/afsample.json").responseJSON { response in
if let JSON = response.result.value {
print(JSON["firstkey"])
}
}
I get the error:
Type 'Any' has no subscript members
I don't know why this error is happening, it seems as if I'm accessing the data correctly. Any help would be great, thanks!
I have tried formatting it using both:
print(JSON["firstkey"] as String)
and
print(JSON["firstkey"] as [String:Any]
but they still give the same error.
This is the JSON on my endpoint:
{
"firstkey":"it worked!",
"secondkey":["item1", "item2", "item3"]
}