let JSONExample_USER = """
{
"userName": "username",
"userId": 1238120
}
"""
struct Users: Decodable {
let name: String
let uuid: Int
enum CodingKeys: String, CodingKey {
case name = "userName"
case uuid = "userId"
}
}
func jsondecoding() {
guard let data = JSONExample_USER.data(using: .utf8) else {
fatalError("JSON 데이터 가지고 오기 실패")
}
do {
let data = try JSONDecoder().decode(Users.self, from: data)
dump(data)
} catch {
print(error)
}
}
jsondecoding()