Swift HTTP网络操作库Alamofire

Alamofire:https://github.com/Alamofire/Alamofire
测试网址:https://httpbin.org/

1.复制此文件到目录
Swift HTTP网络操作库Alamofire_第1张图片
2.导入此框架
3.png

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
                let origin = dict["origin"] as! String
                let url = dict["url"] as! String
                let headers = dict["headers"] as! Dictionary
                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)
            }
        
        })

你可能感兴趣的:(Swift HTTP网络操作库Alamofire)