Ниже приведен мой JSON:
{
"Books":[
{
"title":"book title",
"Contents":[
{
"figure":"Clause33",
"url":"PressureReleifValve.html",
"type":"video"
}
]
}
]
}
Вот структура: содержимое может содержать несколько элементов.
struct Books: Codable {
let title: String
let contents: [Content]
}
struct Content: Codable {
let figure, url, type: String
}
Вот код:
guard let books = try? JSONDecoder().decode(Books.self, from: jsonData2) else {
fatalError("The JSON information has errors")
}
Что не так с моим кодом?