Restaurant Menu Viewer JSON Parser
This commit is contained in:
parent
b91ab9d571
commit
a01a6d9f26
3 changed files with 20 additions and 13 deletions
|
|
@ -14,13 +14,14 @@ struct MenuCard: Codable {
|
||||||
|
|
||||||
struct MenuItem: Codable {
|
struct MenuItem: Codable {
|
||||||
let name: String
|
let name: String
|
||||||
let detailText: String
|
let description: String
|
||||||
|
let imageUrl: URL
|
||||||
// let price: Double
|
// let price: Double
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
// enum CodingKeys: String, CodingKey {
|
||||||
case name
|
// case name
|
||||||
case detailText = "description"
|
// case detailText = "description"
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DataView: View {
|
struct DataView: View {
|
||||||
|
|
@ -42,7 +43,10 @@ struct DataView: View {
|
||||||
) else { return }
|
) else { return }
|
||||||
|
|
||||||
if let response = response as? HTTPURLResponse, response.statusCode == 200 {
|
if let response = response as? HTTPURLResponse, response.statusCode == 200 {
|
||||||
menu = try! JSONDecoder().decode(MenuCard.self, from: data)
|
jsonDecoder.keyDecodingStrategy = .convertFromSnakeCase
|
||||||
|
|
||||||
|
menu = try! jsonDecoder.decode(MenuCard.self, from: data)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,7 +54,14 @@ struct DataView: View {
|
||||||
print(string)
|
print(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text("asdlfaksdf")
|
|
||||||
|
ForEach(menu.items, id: \.name) { item in
|
||||||
|
HStack {
|
||||||
|
AsyncImage(url: item.imageUrl, scale: 12)
|
||||||
|
// Text(item.imageUrl.absoluteString )
|
||||||
|
Text(item.description )
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,6 @@
|
||||||
"comment" : "The title of a section that displays information about the API.",
|
"comment" : "The title of a section that displays information about the API.",
|
||||||
"isCommentAutoGenerated" : true
|
"isCommentAutoGenerated" : true
|
||||||
},
|
},
|
||||||
"asdlfaksdf" : {
|
|
||||||
"comment" : "A placeholder text.",
|
|
||||||
"isCommentAutoGenerated" : true
|
|
||||||
},
|
|
||||||
"Betrag" : {
|
"Betrag" : {
|
||||||
"comment" : "A text field for entering an amount.",
|
"comment" : "A text field for entering an amount.",
|
||||||
"isCommentAutoGenerated" : true
|
"isCommentAutoGenerated" : true
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue