我目前正在使用 AlamofireObjectMapper 创建 JSON 对象。我很难访问 JSON 数组:
这是 JSON 数组:
[
{
"city": "string",
"country": "string",
"county": "string",
}
]
这是功能:
func getMemberDetails ( id: String) {
Alamofire.request(.GET, "\(baseURL)/api/Members/\(id)/memberDetails").responseArray { (response: Response<[MemberDetailInfo], NSError>) in
let memberDetailArray = response.result.value
if let memberDetailArray = memberDetailArray {
for memberDetail in memberDetailArray {
print(memberDetail.createDate)
print(memberDetail.id)
}
}
}
}
这是类:
class MemberDetailInfo: Mappable{
var city: String?
var country: String?
var county: String?
required init?(_ map: Map) {
mapping(map)
}
unc mapping(map: Map) {
city <- map["city"]
country <- map["country"]
county <- map["county"]
}
}
每当我通过它时,它都会直接跳到最后,我不确定它为什么不起作用。如果有人知道如何从数组中提取 JSON 数据,将不胜感激。