为什么我无法将JSON响应中的String值转换为Int?它返回下一个错误:
Cannot invoke initializer for type 'Int' with an argument list of type '(JSON)'
Run Code Online (Sandbox Code Playgroud)
当我尝试:
Int(json[i]["id"])
Run Code Online (Sandbox Code Playgroud)
我怎样才能将它转换为Int?
我假设您使用的是SwiftyJSON.
在这种情况下,您有两个选择:
可选的getter:
if let id = json[i]["id"].int {
// do something
}
Run Code Online (Sandbox Code Playgroud)
非可选的getter:
let id: Int = json[i]["id"].intValue
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4209 次 |
| 最近记录: |