0
votes

I'm using Alamofire to get a data from a JSON file. Example of the output: [{"image_name":"vacation"},{"image_name":"graduation"}]

I have a problem when I try to access the information from the JSON output.

    Alamofire.request(.GET, url).responseJSON { (response) -> Void in
        if let JSON = response.result.value {
            for json in JSON{
                print(json)
            }
        }

The problem I have is that my JSON output is an AnyObject and I cannt iterate over an AnyObject. If I do the following:

print(JSON[0]["image_name"])

Then I can see the output correctly. How can I iterate over an AnyObject?

1

1 Answers

0
votes

You may need to explicitly state the type of JSON as an array of dictionaries:

if let JSON = response.result.value as [[String : AnyObject]] {
    // ...
}