I'm really sorry if this is a bit of a dumb question but I was wondering how I could create a JSON and JSON Decoder that works with the Swift Struct below.
Thanks!
struct Example: Hashable, Codable, Identifiable {
var id: Int
var title: String
var category: String
var year: String
var imageName: String
var bannerName: String
var URLScheme: String
var isFavorite: Bool
struct ProductRow: Codable, Hashable {
let title: String
let value: String
}
let rows: [ProductRow]
}
This can be achieved with some simple instructions.
create an instance of your model:
Then "encode" it with a
JSONEncoder, convert everything to aStringand print it:Output: