Alamofire:https://github.com/Alamofire/Alamofire
测试网址:https://httpbin.org/
1.JSON数据解析
Alamofire.request(.GET, "https://httpbin.org/get")
.responseJSON(completionHandler: {response in
print("JSON ==================")
switch response.result {
case .Success(let json):
let dict = json as! Dictionary<String, AnyObject>
let origin = dict["origin"] as! String
let url = dict["url"] as! String
let headers = dict["headers"] as! Dictionary<String, String>
let ua = headers["User-Agent"]
let host = headers["Host"]
print(dict)
print(origin)
print(ua)
print(host)
print(url)
case .Failure(let error):
print(error)
}
})