По советам форумчан начал использовать AlamofireObjectMapper.
class PostResponse: Mappable {
var posts: [Post]?
required init?(map: Map) {}
func mapping(map: Map) {
self.posts <- map["hits"]
}
}
И второй класс:
class Post: Mappable {
var id: String?
var image: String?
init() {}
init(id: String, image: String) {
self.id = id
self.image = image
}
required init?(map: Map) {
}
func mapping(map: Map) {
id <- map["objectID"]
image <- map["img"]
}
}
У меня такой JSON
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 119,
"max_score": 1,
"hits": [
{
"_index": "v1",
"_type": "sales",
"_id": "-ertertertgfd-8Y",
"_score": 1,
"_source": {
"objectID": "-rtetert-8Y",
"name": "Laboris esse proident ex aliqua officia tempor ad consectetur anim laboris.",
"content": "Et nostrud pariatur ut quis fugiat amet Lorem quis deserunt consequat voluptate. Ut ut commodo non id. Elit velit ea voluptate laborum. Consequat pariatur laborum cillum sit magna occaecat consectetur laborum Lorem. Adipisicing minim irure exercitation quis ut amet ex commodo aliqua.",
"ageLimit": "18+",
"category": {
"categoryName": false,
"categoryID": "house"
},
"location": {
"branches": [
{
"administrativeLevels": {
"level1long": "область",
"level1short": "область",
"level2long": "район",
"level2short": "район"
},
"city": "",
"country": "",
"countryCode": "",
"extra": {
"confidence": 0.9,
"googlePlaceId": "",
"neighborhood": "район"
},
"formattedAddress": "ул. 22,,",
"latitude":,
"longitude":,
"provider": "",
"streetName": "улица",
"streetNumber": "22 "
}
],
"countryId": "",
"regionId": ""
},
"company": {
"companyId": "dfge345r",
"companyName": false,
"content": false,
"img": false,
"phone": [
"+7 (989) 583-2365",
"+7 (885) 457-3090",
"+7 (818) 446-3690",
"+7 (848) 478-2726"
]
},
"publishStatus": true,
"isActive": true,
"img": "-kehrtkehrth454"
}
}
как теперь достать то что внутри _source
Использую Alamofire:
Alamofire.request(url, headers: headers).responseObject { (response: DataResponse<PostResponse >) in
Как мне зайти в “hits” -> “hits” -> “_source”?
Спасибо.