Nsurl, nssession

please can you explain how to pass the json-data in “let result” to a new view e.g. a textfield?

Here is the related piece of code:

// make http POST request
let uploadTask = session.uploadTask(with: request as URLRequest, from: body?.data(using: String.Encoding.utf8)!){
(data, response, error) in

(response as? HTTPURLResponse)?.statusCode

// URL Object to String
let result = String(data: data!, encoding: String.Encoding.utf8)
} 
uploadTask.resume()
1 Like

Hello @jimknopf

I think you want to convert json data into String. And then want to pass that string to any control For ex. you want to set text of UILable or may be set that string into UITextField.

You have done correct. Further just use string as you want :

// make http POST request
let uploadTask = session.uploadTask(with: request as URLRequest, from: body?.data(using: String.Encoding.utf8)!) { (data, response, error) in

    (response as? HTTPURLResponse)?.statusCode

    // URL Object to String
    if data != nil {

        let result = String(data: data!, encoding: String.Encoding.utf8)

        if result != nil && result.characters.count > 0 {

            lblMessage.text = result
        }
    }
} 
uploadTask.resume()

If your response is in format of Dictionary then first convert into Dictionary and then retrieve needed data from that.