标签:get div method text 接口 ons ict failure map
get请求:
Alamofire.request("你的网址",method: .get, parameters: nil, encoding: URLEncoding.default)
.responseJSON { response in
//print("url:\(response.request)") // original URL request
//print("request:\(response.response)") // URL response
//print("data:\(response.data)") // server data
//print("result:\(response.result)") // result of response serializatio
}
let currRequest = Alamofire.request("你的网址", method: .post, parameters: nil, encoding:URLEncoding.default, headers: nil)
currRequest.responseJSON{(responseJson) -> Void in
switch responseJson.result {
case .success(let value):
let swiftyJsonVar = JSON(value)
//将获取的所有的title放到数组里面
// let str = swiftyJsonVar["data"].arrayValue.map({$0["title"].stringValue})
self.resultArr = swiftyJsonVar["data"]
// for index in 1...self.resultArr.count{
// if let str = self.resultArr[index-1]["title"].string {
//
// print(str)
// }
// }
case .failure( _):
// print(error)
ZHBPopTipView.showText("网络错误", position: .bottom)
}
self.tableView.reloadData()
}
post接口并上传字典:
do {
dic = ["key":"value"]
print(mobileDic)
Alamofire.request("你的网址", method: .post, parameters:dic, encoding: URLEncoding.default, headers:nil).responseJSON(completionHandler: { (response)in
switch response.result{
case .success:
iflet dic:NSDictionary = (response.result.value as? NSDictionary){
print(dic)
}
case .failure(let error):
print(error)
}
})
} catch {
print(error)
}
标签:get div method text 接口 ons ict failure map
原文地址:http://www.cnblogs.com/-ios/p/7279367.html