ccy1194021 ccy1194021 - 1 year ago 80
iOS Question

Trying to parse JSON in Swift, but get error

"base": "EUR",
"date": "2016-09-23",
"rates": {
"AUD": 1.4685,
"BGN": 1.9558,
"BRL": 3.5931,
"CAD": 1.4625

I got a json like this, and i tried to get the rates, but got the error, my code like:

let id = json["rates"] as? String
print("rates :" + id!)

I am new to swifty, i want to get each rates separately, can anyone help me? thanks

Answer Source

Try this:

If let id = json["rates"] as? [String:AnyObject] {
    print("rates   :" + id)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download