我尝试使用ModelMapper库的mapObject函数,如下所示:
return provider.request(API.userInfo(userId: API.userId))
.mapObject(type: UserTest.self, keyPath: "user")
{
"success": true,
"user": {
"_id": "HJzCZaXEW",
"mail": "Valentin",
"__v": 0,
"bikes": [
"S1rjHamNZ",
"HkxhHpXEZ"
],
"updated": "2017-06-30T12:19:22.016Z",
"created": "2017-06-30T12:19:22.015Z"
}
}
我试着用这种方法看看有什么错误:
API.getUserInfo()
.subscribe {event in
switch event {
case .next(let response):
print(response)
case .error(let error):
print("error")
print(error)
default:
print("default")
}
}
我在控制台上看到了这个:
error
jsonMapping(Status Code: 200, Data Length: 177)
import Mapper
struct UserTest: Mappable {
var name: String
var lastname: String
var mail: String
var bikes: [String]
init(map: Mapper) throws {
try name = map.from("name")
try lastname = map.from("lastname")
try mail = map.from("mail")
try bikes = map.from("bikes")
}
}
我也尝试过pod更新,但没有任何改变。
提前感谢您的帮助!