有人能告诉我我做错了什么吗?我在这里查看了所有问题,如下所示如何使用Swift Decodable协议解码嵌套的JSON结构?我发现了一个看起来正是我需要的Swift 4 Codable解码json.
{
"success": true,
"message": "got the locations!",
"data": {
"LocationList": [
{
"LocID": 1,
"LocName": "Downtown"
},
{
"LocID": 2,
"LocName": "Uptown"
},
{
"LocID": 3,
"LocName": "Midtown"
}
]
}
}
struct Location: Codable {
var data: [LocationList]
}
struct LocationList: Codable {
var LocID: Int!
var LocName: String!
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "/getlocationlist")
let task = URLSession.shared.dataTask(with: url!) { data, …Run Code Online (Sandbox Code Playgroud)