This was the struct I was using

```
struct earthquakeResults: Codable{
    let datetime: String
    let depth: String
    //let eqid: Any
    let lat: String
    let lng: String
    let magnitude: String
    //let src: Any
}

```

This is when I was trying to get the JSON result, and I used a geocoder to get long/lat which I then used to get the north/south/east/west for the api call

```
let urlAsString = "http://api.geonames.org/earthquakesJSON?north=\(north)&south=\(south)&east=\(east)&west=\(west)&username=antoniogomez"

let url = URL(string: urlAsString)!
        let urlSession = URLSession.shared

        let jsonQuery = urlSession.dataTask(with: url, completionHandler: { data, response, error -> Void in
            if (error != nil) {
                print(error!.localizedDescription)
            }
            var err: NSError?

            let decoder = JSONDecoder()

            let jsonResult = try! decoder.decode([earthquakeResults].self, from: data!)

            if (err != nil) {
                print("JSON Error \(err!.localizedDescription)")
            }

            print(jsonResult)

            let dt = jsonResult[0].datetime
            let dp = jsonResult[0].depth
            let lt = jsonResult[0].lat
            let lg = jsonResult[0].lng
            let mag = jsonResult[0].magnitude

            let res = "Results : \(dt) \(dp) \(lt) \(lg) \(mag)"
            print(res)
})

        jsonQuery.resume()

```

I was getting the error:

> 
> Thread 3: Fatal error: 'try!' expression unexpectedly raised an error:
>  Swift.DecodingError.typeMismatch(Swift.Array,
>  Swift.DecodingError.Context(codingPath: [], debugDescription:
>  "Expected to decode Array but found a dictionary instead.",
>  underlyingError: nil))
> 
> 
> 

this is what the JSON looked like:

```
{
    earthquakes =     (
                {
            datetime = "2012-10-09 10:32:04";
            depth = "10.2";
            eqid = c000d4li;
            lat = "-61.0333";
            lng = "153.9596";
            magnitude = "6.4";
            src = us;
        },
                {
            datetime = "2013-01-15 15:09:36";
            depth = 10;
            eqid = b000epcu;
            lat = "-62.5663";
            lng = "-161.3457";
            magnitude = "6.1";
            src = us;
        },
                {
            datetime = "2019-07-23 10:33:10";
            depth = 10;
            eqid = us70004r4f;
            lat = "-61.2936";
            lng = "154.063";
            magnitude = 6;
            src = us;
        },
                {
            datetime = "2016-01-31 17:43:40";
            depth = 10;
            eqid = us20004w6c;
            lat = "-63.2868";
            lng = "169.1522";
            magnitude = 6;
            src = us;
        },
                {
            datetime = "2016-02-23 18:10:40";
            depth = "7.71";
            eqid = us10004s4c;
            lat = "-63.1275";
            lng = "144.7936";
            magnitude = "5.9";
            src = us;
        },
                {
            datetime = "2017-06-03 19:32:50";
            depth = 10;
            eqid = us20009kit;
            lat = "-62.5792";
            lng = "155.834";
            magnitude = "5.9";
            src = us;
        },
                {
            datetime = "2010-12-24 04:48:54";
            depth = "10.7";
            eqid = c0000ueu;
            lat = "-63.5903";
            lng = "-167.4271";
            magnitude = "5.9";
            src = us;
        },
                {
            datetime = "2007-11-04 19:35:36";
            depth = "7.5";
            eqid = 2007jhax;
            lat = "-67.1317";
            lng = "111.5551";
            magnitude = "5.8";
            src = us;
        },
                {
            datetime = "2007-08-02 22:41:16";
            depth = "11.7";
            eqid = 2007fpab;
            lat = "-62.8736";
            lng = "145.4634";
            magnitude = "5.7";
            src = us;
        },
                {
            datetime = "2006-03-23 12:57:41";
            depth = 10;
            eqid = kqbp;
            lat = "-62.5198";
            lng = "164.8179";
            magnitude = "5.7";
            src = us;
        }
    );
}

```

And this is what I was originally doing, but I couldn't figure out how to get the datetime, and magnitude (or any of the other details) so I figured I would try and use the decoder instead:

```
var jsonResult = (try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers)) as! NSDictionary
if (err != nil) {
    print("JSON Error \(err!.localizedDescription)")
}

```