I try to parse a json that my backend team make. But json kinda weird and I can't ask the backend team to change the json. so Here are the json:
{
"nama": [
"Tigor Franky",
"Achmad Fauzi",
"Mario David Lela Muda",
"Mily Anggreini Hutasuhut",
"Arif Fahmi ST",
"Satwika Narindra Dhipa",
"Mujib Burahman",
"Aresty Puji Harjanty",
"Rio Jatmiko",
"Halasson Sitanggang"
],
"u_id": [
196,
113,
114,
149,
115,
116,
117,
118,
119,
120
],
"totalakhir": [
14.15,
1.74,
1.25,
0.75,
0,
0,
0,
0,
0,
0
]
}
so, this is new to me. How can I decode this?
so far I try this but theres an error that say
"typeMismatch(Swift.Dictionary, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "nama", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "Expected to decode Dictionary but found a string/data instead.", underlyingError: nil))"
I try to make a struct like this:
struct HOF : Codable {
let nama : [Nama]
let u_id : [U_Id]
let totalakhir : [TotalAkhir]
}
struct Nama : Codable {
let namaa : String
enum CodingKeys : String, CodingKey {
case namaa = "nama"
}
}
struct U_Id : Codable {
let u_idd : Int
enum CodingKeys : String, CodingKey {
case u_idd = "u_id"
}
}
I know I'm wrong at making the struct but I just don't know how to make the struct.
let nama : [Nama]bylet nama : [String], and similarly for the other properties ofstruct HOF. - Martin R