Skip to content

Instantly share code, notes, and snippets.

@BasThomas
Created April 17, 2019 15:03
Show Gist options
  • Save BasThomas/be789c9ac64fa2ff60fe144b7dd8f161 to your computer and use it in GitHub Desktop.
Save BasThomas/be789c9ac64fa2ff60fe144b7dd8f161 to your computer and use it in GitHub Desktop.
import Foundation
struct Messages: Decodable {
let count: String
let messages: [Message]
enum CodingKeys: String, CodingKey {
case count = "message-count"
case messages
}
}
struct Message: Decodable {
let receiver: String
let id: String
let status: String
let remainingBalance: String
let price: String
let network: String
enum CodingKeys: String, CodingKey {
case receiver = "to"
case id = "message-id"
case status
case remainingBalance = "remaining-balance"
case price = "message-price"
case network
}
}
let json = """
{
"message-count": "1",
"messages": [{
"to": "1",
"message-id": "2",
"status": "0",
"remaining-balance": "0",
"message-price": "0",
"network": "0"
}]
}
""".data(using: .utf8)!
do {
let object = try JSONDecoder().decode(Messages.self, from: json)
print(object)
} catch {
print(error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment