Например: мне нужно извлечь все значения
Data: [
{
"id": 1,
"title": "some title",
"details": "here are some details",
"userId": 1,
"hidden": false,
"createdAt": "2018-02-14T07:02:33.000Z",
"updatedAt": "2018-02-14T07:02:33.000Z",
"contactId": 1,
"noteimages": [
{
"id": 2,
"imageUrl": "someimage222.jpg",
"userId": 1,
"hidden": false,
"createdAt": "2018-02-14T07:02:58.000Z",
"updatedAt": "2018-02-15T04:41:05.000Z",
"noteId": 1
},
{
"id": 2,
"imageUrl": "someimage222.jpg",
"userId": 1,
"hidden": false,
"createdAt": "2018-02-14T07:02:58.000Z",
"updatedAt": "2018-02-15T04:41:05.000Z",
"noteId": 1
}
]
}
]
Это не работает для меня, я получаю все заметки для одного экземпляра заметки
var notes = Note
var noteImages = NoteImage ....
Alamofire.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in
if response.result.error == nil {
guard let data = response.data else { return }
do {
if let json = try JSON(data: data).array {
print(json)
for item in json {
let title = item["title"].stringValue
let details = item["details"].stringValue
//loop through nested array
for innerItem in item["noteimages"].arrayValue {
let noteImage = NoteImage(imageUrl: innerItem["imageUrl"].stringValue)
self.noteImages.append(noteImage)
}
print("note images: \(self.noteImages)")
let note = Note(title: title, details: details, noteImage: self.noteImages)
self.notes.append(note)
}
//print(response)
completion(true)
}
} catch {
debugPrint(error)
}
} else {
completion(false)
debugPrint(response.result.error as Any)
}
}