注意:我需要使用ObjectMapper,而不是AlamoFireObjectMapper。
如何在不使用JSON的情况下进行映射,而是从responseJSON数据映射到用户?下面的内容试图从responseJSON转到jsonn,然后再返回到数据(作为用户)。我想一定有办法吧?
还是应该使用来自responseData的AlamoFire?
public class User: Mappable {
var username: String?
required public init?(map: Map) {
}
// Mappable
public func mapping(map: Map) {
username <- map["username"]
}
}
Alamofire.request(
url,
method: .get,
headers: headers_employees).responseJSON {
response in
// Map via ObjectMapper
let [User] = Mapper<User>().map(JSONString: JSONString)
}发布于 2017-07-03 09:03:21
map函数还接受JSONObject (Any)或JSON dictionary ([String: Any])。根据响应对象的类型,应该使用适当的方法。
在您的例子中,使用下面的代码来映射JSONResponse
Alamofire.request(
url,
method: .get,
headers: headers_employees).responseJSON {
response in
// Map via ObjectMapper
let [User] = Mapper<User>().map(JSONObject:response.result.value)
}https://stackoverflow.com/questions/43076043
复制相似问题