-4

I am working on decoding JSON data coming from API, and I am stuck in decoding image object having the key with integer value you can see in the screenshot attached, any help should be appreciated.Screenshot

Umair Khan
  • 993
  • 8
  • 14
  • 1
    And how do you want them to be represented in your struct? Is the number important? Else, use a custom `ini(from decoder:)` and manage them. And only the images? Not the keys for the roomId ? – Larme Mar 31 '20 at 09:12
  • Copy paste the code instead of screenshot – PGDev Mar 31 '20 at 09:12
  • If you are responsible for the API send more suitable data. Unlike in PHP Array and Dictionary are completely different in Swift – vadian Mar 31 '20 at 09:19

1 Answers1

0

Using Codable, you can parse the above JSON response using the below model.

struct Room: Decodable {
    let roomId: String
    let name: String
    let images: [String:String?]
}

Now, parse it like,

do {
    let response = try JSONDecoder().decode([String:Room].self, from: data)
    print(response)
} catch {
    print(error)
}
PGDev
  • 23,751
  • 6
  • 34
  • 88