Cómo crear y enviar los datos json al server utilizando un lenguaje rápido

Soy nuevo en el desarrollo de IOS y he comenzado con el lenguaje rápido.

Estoy intentando get el valor de dos campos de text y convertir esos dos campos de text en json y enviar ese json al server receive.php.

Permite concider que los campos de text de remolque son – nombre – pase

¿Cómo creo un Json y lo envío al server cuando se hace clic en un button?

Al usar el método http POST con NSURLSession. Digamos que está llamando al método submitAction al presionar el button de inicio de session

Swift 3

@IBAction func submitAction(sender: AnyObject) { //declare parameter as a dictionary which contains string as key and value combination. considering inputs are valid let parameters = ["name": nametextField.text, "password": passwordTextField.text] as Dictionary<String, String> //create the url with URL let url = URL(string: "http://myServerName.com/api")! //change the url //create the session object let session = URLSession.shanetworking //now create the URLRequest object using the url object var request = URLRequest(url: url) request.httpMethod = "POST" //set http method as POST do { request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) // pass dictionary to nsdata object and set it as request body } catch let error { print(error.localizedDescription) } request.addValue("application/json", forHTTPHeaderField: "Content-Type") request.addValue("application/json", forHTTPHeaderField: "Accept") //create dataTask using the session object to send data to the server let task = session.dataTask(with: request as URLRequest, completionHandler: { data, response, error in guard error == nil else { return } guard let data = data else { return } do { //create json object from data if let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any] { print(json) // handle json... } } catch let error { print(error.localizedDescription) } }) task.resume() }