I have json data that looks like this:
{
"balance": {
"pointsEarned": 3,
"pointsAvailable": 3,
"pointsOnHold": 0,
"pointsConsumed": 0,
"nextReward": 6
}
}
I'm trying to map the "balance" so I can get the other values:
class AccountBalance: Mappable {
var balance: Dictionary<String, AnyObject>?
var pointsAvailable: Int?
required init?(_ map: Map) {
}
func mapping(map: Map) {
balance <- map["balance.value"]
pointsAvailable <- map ["pointsAvailable"]
}
}
According to the objectMapper github page its done this way:
ObjectMapper supports dot notation within keys for easy mapping of nested objects. Given the following JSON String:
"distance" : {
"text" : "102 ft",
"value" : 31
}
You can access the nested objects as follows:
func mapping(map: Map) {
distance <- map["distance.value"]
}
Whenever I try and access the "balance" I get a nil. Any idea what I may be doing wrong?