0

I currently have the following JSON parsing function that is meant to send Params, Parse the response and then display the value of the JSON code string in the textfield.

I am having some issues understanding how params can be implemented into this function.

class A: Codable {
    var code: String?
    var position: String?
    var person: String?
}



 var request = URLRequest(url: URL(string: "example.com/example")!)
 request.httpMethod = "POST"
 URLSession(configuration: .default)
     .dataTask(with: request) { (data, response, error) in
         if let error = error {
             DispatchQueue.main.async {
                 failure(error)
             }
             return
         } else if let model = try! JSONDecoder().decode(A.self, from: data) {

              exampleTextField.text = model.code
         }
    }

JSON Response that is sent when the proper params are sent:

{
    "code": "WE3049320",
    "position": "Instructor",
    "person": "Jeff"
}

0 Answers0