1. Если ваш JSON
ответ такой:
{
"code": 200,
"msg": "Verification_OTP",
"result": {
"customer_email": "ghg@Gmail.com",
"customer_name": "we",
"customer_phone": 1234567890,
"otp": 658715,
"user_id": 135
}
}
2. Ваши Codable
модели будут выглядеть так:
struct Response: Codable {
let code: Int
let msg: String
let result: Result
}
struct Result: Codable {
let customerEmail: String
let customerName: String
let customerPhone: Int
let otp: Int
let userId: Int
}
3. Разобрать data
с вышеуказанными моделями, такими как:
do {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let response = try decoder.decode(Response.self, from: data)
print(response)
} catch {
print(error)
}