将 JSON 结果传递给第二个 Web 服务以使用 Alamofire Swift 获得最终结果

Pass JSON result to second webservice to get final results using Alamofire Swift

我有两个 Web 服务并使用 Alamofire。

想要实现:将第一个 Web 服务 json 数据传递给第二个 Web 服务(参数)或任何建议以获得最终数据。 请任何人帮助....

第一个 Web 服务:

Alamofire.request("http://GetConstantTableList", method: .get, encoding: encoding, headers: [ "Accept":"application/json", "Authorization":"Bearer \(token ?? "")"])
.responseJSON { respo in
print(respo)

结果第一个 Web 服务:

{
    "items": [
        {
            "actionType": 101,
            "version": 1
        },
        {
            "actionType": 1015,
            "version": 1
        }

        ]
}

第二个网络服务:

Alamofire.request("http://GetConstantTableData", method: .post, parameters: ???  encoding: encoding, headers: [ "Accept":"application/json", "Authorization":"Bearer \(token ?? "")"])
.responseJSON { response in
print(response)
}

您可以通过在第一个 api 的响应块中调用第二个 api 直接传递第一个 api 的响应。

private func callFirstApi() {
    Alamofire.request("http://GetConstantTableList", method: .get, encoding: encoding, headers: [ "Accept":"application/json", "Authorization":"Bearer \(token ?? "")"])
        .responseJSON { response in
            switch response.result {
            case .success(let value):
                if let parameters = value as? [String: Any] {
                    callSecondApi(with: parameters)
                }

            case .failure(let error):
                print(error.localizedDescription)
            }
    }
}

private func callSecondApi(with parameters: [String: Any]) {
    Alamofire.request("http://GetConstantTableData", method: .post, parameters: parameters, encoding: encoding, headers: [ "Accept":"application/json", "Authorization":"Bearer \(token ?? "")"])
        .responseJSON { response in
            print(response)
    }
}