I'm now starting to use alamofire, I was able to quietly make requests .get however I crashed the post request.
I created a user class that has name, email and password, however I can not post a user stay object
let usuario = Usuario()
usuario.nome = "Kleiton"
usuario.senha = "1234"
usuario.email = "[email protected]"
do{
let usuarioJson = try NSJSONSerialization.dataWithJSONObject(usuario, options: NSJSONWritingOptions())
Alamofire.request(.POST, "ws/inserir", parameters: usuarioJson as AnyObject as? [String : AnyObject]).responseJSON(completionHandler: { (response) in
print(response.result)
})
}catch{
}
I may be wavering somewhere, I tried to pass the object to json let usuarioJson = try NSJSONSerialization.dataWithJSONObject(usuario, options: NSJSONWritingOptions())
but I get the following error
uncaught exception 'NSInvalidArgumentException', reason: '*** + [NSJSONSerialization dataWithJSONObject: options: error:]: Invalid top-level type in JSON write '
Can anyone tell me if this is the correct way to do a post? How to pass the object to json in the correct way?