2016-10-27 67 views
1

我有一個UITableView這樣的:的iOS使用JSON陣列迅速的tableView頭

enter image description here

tableView數據從JSON取得與AlamofireSwiftyJson

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) 

       ... 
      } 

     } 
    } 
+0

爲什麼你使用的循環,你只需要在一個陣列中的數據,並只需填寫入臺 –

+0

https://grokswift.com/rest-with-alamofire-swiftyjson/參考此鏈接 –

回答