When I try to decode JSON it gives me the dataCorrupted error with debugDescription: "The given data was not valid JSON."
Model:
import Foundation
struct Test: Codable {
var data: [Coordinate]
}
struct Coordinate: Codable {
let id: Int
let latit: Double
let longit: Double
}
JSON:
Request code:
func requestSpots() async {
let url = URL(string: "http://37.143.66.25:9875/spots/get-all")!
var request = URLRequest(url: url)
request.setValue("x-access-token", forHTTPHeaderField: token)
request.httpMethod = "GET"
do {
let (data, _) = try await URLSession.shared.data(for: request)
do {
let decodedSpot = try JSONDecoder().decode(Test.self, from: data)
print(decodedSpot)
} catch {
print(String(describing: error))
}
} catch {
print("Request spots failed")
}
}```