我尝试实施Alamofire给出的示例:https://github.com/Alamofire/Alamofire#generic-response-object-serialization
问题是我想在请求之后获取完成处理程序的用户对象:
Alamofire.request(.GET, "https://example.com/users/mattt")
.responseObject { (response: Response<User, NSError>) in
debugPrint(response)
}
有人知道如何从响应中访问用户对象吗?
答案 0 :(得分:1)
您可以使用User
类似:
response.result.value!
对象
Alamofire.request(.GET, "https://example.com/users/mattt")
.responseObject { (response: Response<User, NSError>) in
debugPrint(response)
print(response.result.value!.username) //It will print username if `username` key belongs to your User object.
}
希望这会有所帮助!