Backend returns custom JSON value for location. As shown in example:
{
"location": (54.000000, 21.000000)
}
For parsing JSON I am using this code:
let json = """
{
"location": (54.000000, 21.000000)
}
"""
struct Location: Codable {
var latitude: Double
var longitude: Double
}
let dataJson = json.data(using: .utf8)!
let location = try? JSONDecoder().decode(Location.self, from: dataJson)
When I am trying to create Location object using JSONDecoder it gives me an error: The given data was not valid JSON.
dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 18." UserInfo={NSDebugDescription=Invalid value around character 18.})))
I know that it is not valid JSON. Which methods to override that I could parse invalid JSON values?