我有一個UITableView
這樣的:的iOS使用JSON陣列迅速的tableView頭
和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",
}
]
}
}
}
我的問題是我如何分隔城市的地方在一個數組中繼承類名爲Pla並將數據放在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)
...
}
}
}
爲什麼你使用的循環,你只需要在一個陣列中的數據,並只需填寫入臺 –
https://grokswift.com/rest-with-alamofire-swiftyjson/參考此鏈接 –