简体   繁体   English

类型“codechefRoot”不符合协议可解码

[英]Type "codechefRoot" does not conform to protocol Decodable

Why is it the error occurring only for "codechefRoot" while other struct objects work just fine?为什么错误只发生在“codechefRoot”而其他结构对象工作正常?

I mean codechefRoot is as same as other struct objects, why the error occurring only at it.我的意思是 codechefRoot 与其他 struct 对象一样,为什么错误只发生在它上面。

import Foundation

struct codeforcesRoot: Decodable {
    var status: String
    var result: [codeforcesData]
}

struct codeforcesData: Decodable {
    var handle: String
    var rank: String
    var rating: Int
}

struct interviewbitRoot: Decodable {
    var rank: String
    var score: String
    var streak: String
}

struct codechefRoot: Decodable {
    var rank: String
    var global_rank: String
    var country_rank: String
    var contest: [contestsData]
}

struct contestsData {
    var name: String
    var rating: String
    var global_rank: String
    var country_rank: String
}

You get this error because your contestsData type does not conform to Decodable .您收到此错误是因为您的contestsData类型不符合Decodable

By changing struct contestsData {..}通过改变struct contestsData {..}
to struct contestsData: Decodable {..} should fix it struct contestsData: Decodable {..}应该修复它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM