【发布时间】:2017-05-17 08:41:24
【问题描述】:
这是我的网址回复
{
"base": "EUR",
"date": "2017-05-16",
"rates": {
"AUD": 1.492,
}}
这是我的代码
Alamofire.request("http://api.fixer.io/latest").responseJSON { response in
guard let JSON = response.result.value else{
print("Error")
return
}
print("JSON: \(JSON)")
let dict = JSON as! NSDictionary
let base : String = dict["base"] as! String
print("Base:", base)
let date : String = dict["date"] as! String
print("Date:", date)
let rateDict = dict["rates"] as! NSDictionary
let aud : String = rateDict["AUD"] as! String
print("AUD:", aud)
}
行 let aud : String = rateDict["AUD"] as!字符串 上面标题中提到的消息有错误。这里发生了什么事。请任何人帮助我。
【问题讨论】:
-
它是一个数字,您尝试将其强制转换为字符串,这就是正在发生的事情 - 顺便说一下,错误消息清楚地说明了这一点。看一下json就知道1.492周围没有""
标签: json swift casting nsdictionary