请告诉我提取"排名"的价值的方法。首先检查图像。
我的结构:
struct Result2 : Codable{
let rankings : [Myrankings3]
struct Myrankings3 : Codable{
let ranking : String
}
}
JSON代码
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
}
答案 0 :(得分:0)
在根对象(finalResult
)中迭代数组rankings
let finalResult = try JSONDecoder().decode(Result2.self, from: data!)
for myRanking in finalResult.rankings {
print(myRanking.ranking)
}