无法使用 swift JSON 解码器从结构中提取值
unable to extract value from struct using swift JSON Decoder
Click Here for JSON image
请告诉我提取"ranking"值的方法。首先检查图像。
我的结构:
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
}
在根对象(finalResult
)中迭代数组rankings
let finalResult = try JSONDecoder().decode(Result2.self, from: data!)
for myRanking in finalResult.rankings {
print(myRanking.ranking)
}
Click Here for JSON image
请告诉我提取"ranking"值的方法。首先检查图像。
我的结构:
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
}
在根对象(finalResult
)中迭代数组rankings
let finalResult = try JSONDecoder().decode(Result2.self, from: data!)
for myRanking in finalResult.rankings {
print(myRanking.ranking)
}