struct Product: Codable {
var id: String?
var product: String?
var description: String?
var price: String?
var feed: String?
var quantity: String?
var image: String?
}
'мой локальный файл JSON. Глядя на путь к файлу и открывая его локально, кажется, что данные JSON находятся в правильном формате. В моем файле products.json данные настроены так. '
{
"products" : [
{
"id": "1",
"product" : "Rus Salatası...",
"image" : "imageURL...",
"description" : "description...",
"price" : "3.25",
"feed" : "Bu menü 1 kişiliktir..",
"quantity" : "1"
}
]
}
' Код декодирования JSON '
guard let jsonFile = Bundle.main.path(forResource: "products", ofType: "json") else { return }
guard let data = try? Data(contentsOf: URL(fileURLWithPath: jsonFile), options: []) else { return }
do {
let plantDataSerialized = try JSONDecoder().decode(Product.self, from: data)
print("Test: \(plantDataSerialized)")
} catch let error{
print(error.localizedDescription)
}
' Я не могу получить данные. Как я могу получить данные. plantDataSerialized всегда ноль. «