AF.request("http://gank.io/api/xiandu/categories",method: .get,parameters: nil).responseJSON { (response) in
switch response.result {
case .success:
let json = JSON(response.value!)
let results = json["results"]
for (_,subJson):(String,JSON) in results {
let category = Category(jsonData: subJson)
print(category)
}
case .failure:
print("failure")
}
}
import Foundation
import SwiftyJSON
class Category {
var id:String
var enName:String
var name:String
var rank:Int
init(jsonData:JSON) {
id = jsonData["_id"].string!
enName = jsonData["en_name"].string!
name = jsonData["name"].string!
rank = jsonData["rank"].int!
}
}