简体   繁体   中英

How to get Alamofire response json from responseDecodable?

I am wondering if there is a way to retrieve the response json from AF even if using the responseDecodable method:

AF.request(APIRouter.testGet).responseDecodable(decoder: jsonDecoder) { (response: DataResponse<[ObjectA], AFError>) in
            completion(response.result)
        }

I am asking this because even using the usual responseJSON it seems the JSON completion parameter is not missing.

response.data will contain the raw data you received. In the case of JSON, this can be converted to the JSON string when supplied with the right encoding:

AF.request(APIRouter.testGet).responseDecodable(decoder: jsonDecoder) { (response: DataResponse<[ObjectA], AFError>) in
        if let data = response.data {
            print(String(data: data, encoding: .utf8)!)
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM