-4

Click Here for JSON image

Please tell me the way to extract the value of "ranking". Check the image first.

My struct :

struct Result2 : Codable{
    let rankings : [Myrankings3]

    struct Myrankings3 : Codable{
        let ranking : String
    }
}

JSON code

do {
    let finalResult = try JSONDecoder().decode(Result2.self, from: data!)
    print(finalResult)        
    // I want to get the value of ranking which is of type string 
}
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
girija
  • 1
  • 2

1 Answers1

0

In the root object (finalResult) iterate the array rankings

let finalResult = try JSONDecoder().decode(Result2.self, from: data!)
for myRanking in finalResult.rankings {
      print(myRanking.ranking)
}
vadian
  • 274,689
  • 30
  • 353
  • 361