Post

Replies

Boosts

Views

Activity

Unable to parse JSON using decode function
Hi, I have a problem when trying to parse the JSON which used to work before but it is broken now and I have no idea why it is. JSON data: { "success": true, "data": { "email": "example@gmail.com", "password": "$2b$10$flI1flm1Ptas33z3uBct6.UkhgiRmv/qIzJCVe2PIUycUFIh0BZfW", "favouriteRestaurants": [], "favouriteDishes": [], "_id": "655adf2386348c2be2360852", "reservations": [], "createdAt": "2023-11-20T04:22:59.831Z", "updatedAt": "2023-11-20T04:22:59.831Z", "__v": 0 } } And my model is struct SignupResponse: Decodable { let email: String? let password: String? let id: String? private enum CodingKeys: String, CodingKey { case data case email case password case id = "_id" } init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) let dataContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data) email = try dataContainer.decodeIfPresent(String.self, forKey: .email) password = try dataContainer.decodeIfPresent(String.self, forKey: .password) id = try dataContainer.decodeIfPresent(String.self, forKey: .id) } I couldn't figure out the reason. Thank you for your help!
1
0
367
Nov ’23