Json
{
"User":[
{
"FirstUser":{
"name":"John"
},
"Information":"XY",
"SecondUser":{
"name":"Tom"
}
}
]
}
Модель
// MARK: - Empty
struct Root: Codable {
let user: [User]
enum CodingKeys: String, CodingKey {
case user = "User"
}
}
// MARK: - User
struct User: Codable {
let firstUser: FirstUserClass
let information: String
let secondUser: FirstUserClass
enum CodingKeys: String, CodingKey {
case firstUser = "FirstUser"
case information = "Information"
case secondUser = "SecondUser"
}
}
// MARK: - FirstUserClass
struct FirstUserClass: Codable {
let name: String
}
Разобрать
do {
let res = try JSONDecoder().decode(Root.self, from: data)
print(res.first?.firstUser.name)
} catch {
print(error)
}