我有一个UITableView
这样的:
以及使用和tableView
从 JSON 中获取数据:Alamofire
SwiftyJson
JSON数据:
{
"timeline": {
"Milan": {
"place": [
{
"name": "Place 1",
"kind": "historic",
},
{
"name": "Place 2",
"kind": "historic",
},
{
"name": "Place 3",
"kind": "historic",
},
{
"name": "Place 4",
"kind": "historic",
}
]
},
"Paris": {
"place": [
{
"name": "Place 1",
"kind": "historic",
},
{
"name": "Place 2",
"kind": "historic",
},
{
"name": "Place 3",
"kind": "historic",
}
]
}
}
}
我的问题是我如何将城市地点分隔在一个从名为 Place 的类继承的数组中,并将数据放入 tableView 中,如上图所示。
struct Place {
var name = ""
var type = ""
}
我写了一些代码,Alamofire
.success
但这还不够:
if let jsonData = response.result.value {
let json = JSON(jsonData)
if let items = json["timeline"].dictionary {
for (key,subJson):(String, JSON) in items {
self.cityName.append(key)
...
}
}
}