JASON
JASON copied to clipboard
Decoding large Double
This code makes the exception:
struct Response: Codable {
let success: Bool
let value: Double
}
func testJASON() {
let string: String =
"""
{"success":true,"value":100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000≥0}
"""
let data = string.data(using: .utf8)!
let json = JASON.JSON(data)
let val = json["value"].double
print("\(val)")
}
If you remove one of zeroes in "string" then the decoding will be OK. So the limit is 1e165, after which the decoding fails regardless of Double type can really fit.