Swift 3 / JSON - How to capture List of objects within an object?

1

How do I access a list of objects within another object list? I can capture these objects quietly, but I'm having trouble capturing objects within this list. Here's my JSON:

InthiscaseIwanttohaveaccesstothevaluesthatarewithin"NOTES" and "FAULTS" but I am not having much success in this ...
Here is my code:

 for item in resultado!{

    let newDisc = DisciplinasML()

    newDisc.codDisciplina = item["COD_DISCIPLINA"]! as? String
    newDisc.desDisciplina = item["DES_DISCIPLINA"]! as? String
    newDisc.desPeriodo = item["DES_PERIODO"]! as? String
    newDisc.medDisciplina = item["MEDIA_DISCIPLINA"]! as? String
    newDisc.nomProfessor = item["NOM_PESSOA_PROF"]! as? String
    newDisc.perFaltas = item["PERCENTUAL_AULAS"]! as? String

       //Eu acho que não seja assim que se capture o valor
       for nota in (item["NOTAS"]! as! NSArray){

           //nota has no subscription members     
           print(nota["COD_AVALIACAO"] as String)

       }
        //Adiciono os itens na lista
        self.listDisciplinasWS.append(newDisc)
 }

Any tips? Home Thanks for all the help

    
asked by anonymous 20.02.2017 / 22:02

1 answer

1

Instead of using NSArray try using Swift's native types, because using NSArray the compiler will not be able to infer that the array contains dictionaries within it.

for item in resultado!{

    let newDisc = DisciplinasML()

    newDisc.codDisciplina = item["COD_DISCIPLINA"]! as? String
    newDisc.desDisciplina = item["DES_DISCIPLINA"]! as? String
    newDisc.desPeriodo = item["DES_PERIODO"]! as? String
    newDisc.medDisciplina = item["MEDIA_DISCIPLINA"]! as? String
    newDisc.nomProfessor = item["NOM_PESSOA_PROF"]! as? String
    newDisc.perFaltas = item["PERCENTUAL_AULAS"]! as? String

    // Modificação ocorre nessa parte do código
    for nota in (item["NOTAS"]! as! [[String:Any]]){

       //nota has no subscription members     
       print(nota["COD_AVALIACAO"] as! String)

    }

    self.listDisciplinasWS.append(newDisc)
}
    
21.02.2017 / 06:26