I have a simple question: how to convert such a json response to object with usage of Hearst-DD/ObjectMapper
{
"errors": [
{
"code": "404",
"message": "Wrong id"
}
]
}
With swiftyJson i do
json["errors"][0]["code"]
but how to do it with objectmapper ? i tried this:
map["errors.code"]
and it does not work
EDIT: i did Error and ErrorResponse clasess like suggested, now:
//...
let fullAddress = mainAddress + additionalAddr
var parameters = ["email":email]
manager.GET( fullAddress,
parameters: parameters,
success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
//here is success, i got it done with user mapping
callback(success: true)
},
failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
let errorResponse = Mapper<ErrorResponse>().map(operation.responseString!)
println(errorResponse!) //this prints: MyApp.ErrorResponse
println(errorResponse?.errors!) //this prints: Optional([MyApp.Error])
println(errorResponse?.errors![0]) //this prints:Optional(MyApp.Error)
println(errorResponse?.errors![0].code) //<- this is nil :(
// how to get the code mapped ?
callback(success: false)
})
}