Hello, I am getting this error I have no idea how fix and would appreciate some assistance please:
failed to convert The data couldn’t be read because it isn’t in the correct format.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let url = "https://www.goedash.com/_functions/quoteapi/quote"
getData(from: url)
}
private func getData(from url: String) {
let task = URLSession.shared.dataTask(with: URL(string: url)!, completionHandler: {data, response, error in
guard let data = data, error == nil else {
print("something went wrong")
return
}
// have data
var result: Quote?
do {
result = try JSONDecoder().decode(Quote.self, from: data)
}
catch {
print("failed to convert \(error.localizedDescription)")
}
guard result != nil else {
return
}
print(result!.brandName.codingKey.stringValue)
})
task.resume()
}
}
{
"pickup": {
"street": "26 Broadway",
"city": "New York City",
"state": "NY",
"postalCode": "10004",
"country": "US",
"latitude": 40.716038,
"longitude": -74.00631,
"unit": "104B",
"instructions": "Use back entrance"
},
"dropoff": {
"street": "312 Broadway",
"city": "New York City",
"state": "NY",
"postalCode": "10004",
"country": "US",
"latitude": 40.24377,
"longitude": -74.10277,
"unit": "Suite 300",
"instructions": "Leave with security guard"
},
"quoteExternalReference": "basket_e699aece",
"pickupTime": "2015-09-22T18:30:00.000Z",
"dropoffTime": "2015-09-22T18:30:00.000Z",
"controlledContents": "Alcohol,Tobacco",
"allowedVehicles": "Walker,Bicycle,DeliveryBicycle,Car,Van",
"orderValue": 22.5,
"brandName": "BigBellyBurger",
"currency": "USD",
"storeId": "Store-12345"
}
import Foundation
// MARK: - Quote
struct Quote: Codable {
let pickup, dropoff: Location
let quoteExternalReference, pickupTime, dropoffTime, controlledContents: String
let allowedVehicles: String
let orderValue: Double
let brandName, currency, storeID: String
enum CodingKeys: String, CodingKey {
case pickup, dropoff, quoteExternalReference, pickupTime, dropoffTime, controlledContents, allowedVehicles, orderValue, brandName, currency
case storeID = "storeId"
}
}
// MARK: - Dropoff
struct Location: Codable {
let street, city, state, postalCode: String
let country: String
let latitude, longitude: Double
let unit, instructions: String
}