1
我想首次使用AlamofireObjectMapper來解析一個json響應。AlamofireObjectMapper in swift
的迴應是:
{
"city": {
"total": 19,
"data": [
{
"business_model": 2,
"type": "Hotel"
},
{
"business_model": 2,
"type": "Hotel"
}
]
}
}
我映射這樣的:
class CityResponse: Mappable {
var location: String?
var data: [Data]?
required init?(_ map: Map){
}
func mapping(map: Map) {
data <- map["city.data"]
}
}
class Data: Mappable {
var business_model: String?
required init?(_ map: Map){
}
func mapping(map: Map) {
business_model <- map["business_model"]
}
}
而且在我的控制器:
Alamofire.request(.GET, "MY_URL").responseArray { (response: Response<[Data], NSError>) in
print("res: \(response)")
let forecastArray = response.result.value
if let forecastArray = forecastArray {
for forecast in forecastArray {
print("model is : \(forecast.business_model)")
}
}
}
它給我的錯誤映射。