我正在使用ObjectMapper将 JSON 映射到 Swift 对象。
我有以下 Swift 对象:
class User: Mappable {
var name: String?
var val: Int?
required init?(map: Map) { }
func mapping(map: Map) {
name <- map["name"]
val <- map["userId"]
}
}
Run Code Online (Sandbox Code Playgroud)
我有这个 JSON 结构:
{
"name": "first",
"userId": "1" // here is `String` type.
},
{
"name": "second",
"userId": 1 // here is `Int` type.
}
Run Code Online (Sandbox Code Playgroud)
映射JSON后,其中的userId值为null 。Username"first"
我怎样才能映射Int/String到Int?