我正在尝试使用Codable调用API,并且我想从API访问所有的dictionary,数组。
从codable是否可以做到这一点
接口响应例如:
{
"status": true,
"logo": "https://abc.png",
"data": [
{
"crumb": {
"Menu": {
"navigate": "Home",
},
},
"path": "2",
"type": "type0",
"orientation": [
{
"name": "All",
}
],
},
]
}发布于 2019-04-22 17:39:39
您发布的API响应是无效的JSON (它有一堆后缀逗号,这使其非法)。这需要在生产者端进行更改,完成后,您可以使用此结构来访问数据:
struct Entry: Codable {
let status: Bool
let logo: String
let data: [Datum]
}
struct Datum: Codable {
let crumb: Crumb
let path, type: String
let orientation: [Orientation]
}
struct Crumb: Codable {
let menu: Menu
enum CodingKeys: String, CodingKey {
case menu = "Menu"
}
}
struct Menu: Codable {
let navigate: String
}
struct Orientation: Codable {
let name: String
}https://stackoverflow.com/questions/55792132
复制相似问题