How can I print the json content of the response from post request in Alamofire in swift?

Viewed 7607

Ok, so I'm using alamofire and the parameters I'm passing are valid. Here is the code so far:

Alamofire.request(.POST, "http://mywebservice.com", parameters: myparameters)
.response { (request, response, data, error) in
    if(error != nil){
        print("error= \(error)")
    }else{
        print("there was no error so far ")
        print(data)
        var json = JSON(data!)

        print(json) //prints unknown
        print(json["id"]) //prints null      
        }
    }
}

I tried different things but so far nothing worked. I'm using alamofire and swiftyjson, the response json that comes from webservice is:

{
  "id": "432532gdsg",
  "username": "gsdgsdg"
}

and I want to print both values separately in case of success. How can I do it?

2 Answers
Related