Correctly Parsing JSON in Swift 3
<p>I'm trying to fetch a JSON response and store the results in a variable. I've had versions of this code work in previous releases of Swift, until the GM version of Xcode 8 was released. I had a look at a few similar posts on StackOverflow: <a href="https://stackoverflow.com/questions/33324766/swift-2-parsing-json-cannot-subscript-a-value-of-type-anyobject?noredirect=1&amp;lq=1">Swift 2 Parsing JSON - Cannot subscript a value of type 'AnyObject'</a> and <a href="https://stackoverflow.com/questions/38155436/json-parsing-in-swift-3">JSON Parsing in Swift 3</a>. </p>

<p>However, it seems the ideas conveyed there do not apply in this scenario.</p>

<p>How do I correctly parse the JSON reponse in Swift 3? 
Has something changed in the way JSON is read in Swift 3?</p>

<p>Below is the code in question (it can be run in a playground):</p>

<pre><code>import Cocoa

let url = "https://api.forecast.io/forecast/apiKey/37.5673776,122.048951"

if let url = NSURL(string: url) {
    if let data = try? Data(contentsOf: url as URL) {
        do {
            let parsedData = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments)

        //Store response in NSDictionary for easy access
        let dict = parsedData as? NSDictionary

        let currentConditions = "\(dict!["currently"]!)"

        //This produces an error, Type 'Any' has no subscript members
        let currentTemperatureF = ("\(dict!["currently"]!["temperature"]!!)" as NSString).doubleValue

            //Display all current conditions from API
            print(currentConditions)

            //Output the current temperature in Fahrenheit
            print(currentTemperatureF)

        }
        //else throw an error detailing what went wrong
        catch let error as NSError {
            print("Details of JSON parsing error:\n \(error)")
        }
    }
}
</code></pre>

<p><strong>Edit:</strong> Here is a sample of the results from the API call after <code>print(currentConditions)</code></p>

<pre><code>["icon": partly-cloudy-night, "precipProbability": 0, "pressure": 1015.39, "humidity": 0.75, "precipIntensity": 0, "windSpeed": 6.04, "summary": Partly Cloudy, "ozone": 321.13, "temperature": 49.45, "dewPoint": 41.75, "apparentTemperature": 47, "windBearing": 332, "cloudCover": 0.28, "time": 1480846460]
</code></pre>