1
I’m starting now to use the still, I managed to make requests . get but stopped in post request.
I created a user class that has name, email and password, however I can’t post a user 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 faltering 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'
Could someone tell me if this is the right way to do a post? How to pass the object to json in the right way?
Swift 2 or Swift 3? I don’t know how you do using Alamofire, if you want I can show how you do a post json using Urlrequest and Urlsession (Swift 3) or Nsurlsession (Swift 2).
– Leo Dabus
Swift 2, every solution is life well ;)
– Kleiton Batista
Kleiton speaks from a look at the answer any doubt tells me. If you need help to convert string back to image also just talk. abs
– Leo Dabus
Thank you Leo Dabus, was of great help your solution. Hugs
– Kleiton Batista
You’re welcome Kleiton. Abs
– Leo Dabus