从alamofire获取数据(responseString)

时间:2018-05-30 07:00:56

标签: ios swift alamofire swift4.1

我正在检索使用此代码的数据

 Alamofire.request(urlString, method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: headers)
        .responseString() { response in
            switch response.result {
            case .success(let data):
                let jsonData = JSON(data)
                print(jsonData)

            case .failure(let error):
                print("\(error) - hello world")
            }
    }

并且服务器发送的结果是

{"result":"Opertion is successfull"}

但我只想要价值部分"Opertion is successfull"

1 个答案:

答案 0 :(得分:0)

使用almofire documentation

中的代码
Alamofire.request(urlString, method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: headers)
    .responseString() { response in
        if let jsonData = response.result.value {
            print("JSON: \(jsonData)") // serialized json response
        }
}