Reputation: 771
I have the following struct
:
struct CustomerEntries: Codable {
var date: String
var customer_rate: Double
var percentage: Double
enum CodingKeys: String, CodingKey {
case date
case customer_rate = "customer-rate"
case percentage = "percentage-change"
}
}
I decode JSON using Alamofire's serializingDecodable()
such as this:
let response = await AF.request("https://api.xx.com/endpoint", parameters: params, headers: headers)
.validate()
.serializingDecodable(CustomerEntries.self)
.response
It works fine for the first few results (I traced it), and eventually the response fails for a specific return value of 2.87 for customer_rate
with the error "Number 2.87 is not representable in Swift".
The JSON returned value is:
"customer-rate": 2.87
I tried decoding to String
instead but since the JSON returned value is not enclosed in double quotes, this time the response fails with the error "Expected to decode String but found number instead".
Any ideas on how to resolve this?
Upvotes: 1
Views: 440