你可以通過通JSON
數據作爲編碼參數,Encoding
在Alamofire
如果你要處理的響應JSON數據相當於AFJSONRequestSerializer
request = Alamofire.request(.POST, webServicesURL, parameters: parameters, encoding: .JSON, headers: self.headers)
,只是要求
//This will give you response in JSON
request?.responseJSON { response in
switch response.result
{
case .Success:
success(response: response.result.value)
case .Failure(let error):
failure(error: error)
}
}
requestJSON
相當於到Alamofire的AFJSONResponseSerializer
或者如果你想通過自定義頁眉,傳遞一個字典作爲
let headers = [
"Content-Type": "application/json"
]
//Here we are passing the header in header parameter.
request = Alamofire.request(.POST, webServicesURL, parameters: parameters, encoding: .JSON, headers: self.headers)
好吧,我會試試看。 –
另一個Question'success(response:response.result.value)'是alamofire的默認塊,或者它是由您創建的自定義塊。 –
實際上,它的一切都取決於你,我如何編寫成功塊並相應地處理開關塊 –