[Solved] Place JSON data in label in Swift [duplicate]


Try using Codable to parse the JSON response.

Create the models like,

struct Root: Decodable {
    let data: Response
}

struct Response: Decodable {
    let timeIn: String
    let timeOut: String
}

Now parse your JSON data like,

if let data = data {
    do {
        let decoder = JSONDecoder()
        decoder.keyDecodingStrategy = .convertFromSnakeCase
        let response = try decoder.decode(Root.self, from: data)
        print(response)
    } catch {
        print(error)
    }
}

Get the timeIn and timeOut values using response like,

let timeIn = response.data.timeIn
let timeOut = response.data.timeOut

You can use these timeIn and timeOut values inside your label's text.

8

solved Place JSON data in label in Swift [duplicate]