Alamofire 分别获取响应主体

Alamofire getting response body separately

我无法将响应正文与响应分开。 Alamofire 请求-

AF.request(www.example.com, method: .post, parameters: parameters).response{
response in
debugPrint(response)
self.label_1.text - "Response Body:\(response)"
}

响应-

[Response]: 

[Status Code]: 200

[Headers]:

Content-Encoding: gzip

Content-Length: 51

Content-Type: text/html; charset=UTF-8

Date: Wed, 12 Feb 2020 01:23:39 GMT

Keep-Alive: timeout=5, max=500

Server: Apache/2.2

Vary: Accept-Encoding

Via: 1.1 alproxy

[Response Body]: 

New record created successfully

[Data]: 31 bytes

[Network Duration]: 0.4341869354248047s

[Serialization Duration]: 0.0s

[Result]: success(Optional(31 bytes))

如何从响应中获取 "New record created successfully"? 同样在我的数据库服务中,有时响应将是一个对象数组(这里是一个字符串),如果我想获取一个数组,代码是否会不同于获取一个字符串(如本例)?

如果您阅读 DataResponse type 的文档,您会发现可以通过访问其属性来访问 response 的组件。在您的情况下,您希望访问 value 属性,默认情况下是 Data?。如果您希望解析 String 值,则需要使用 responseString 处理程序,而不仅仅是 response,因此您会自动为您创建 String