繁体   English   中英

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

[英]Type does not conform to protocol 'Decodable' or "Encodable"

我对编程还很陌生,我修复了一些错误,但只剩下一个错误,其中指出:类型“DataClass”不符合第 14 行的协议“Decodable”和类型“DataClass”不符合协议“Encodable”。

我检查了 smiliar 问题,但我不太确定如果我输入 init 是否能找到解决方案

// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse the JSON, add this file to your project and do:
//
//   let welcome = try? newJSONDecoder().decode(Welcome.self, from: jsonData)

import Foundation

// MARK: - Welcome
struct Welcome1: Codable {
    let data: DataClass
}

// MARK: - DataClass
struct DataClass: Codable {
    let id: Int
    let entityType, label: String
    let apiURL, abgeordnetenwatchURL: String
    let firstName, lastName: String
    let birthName: String
    let sex: String
    let yearOfBirth: Int
    // let party: Referenz -> Party???
    let partyPast: String
    let education: String
    let residence: String
    let occupation: String
    let statisticQuestions: Int
    let statisticQuestionsAnswered: Int
    let qidWikidata, fieldTitle: String

    enum CodingKeys: String, CodingKey {
        case id = "id"
        case entityType = "entity_type"
        case label = "label"
        case apiURL = "api_url"
        case abgeordnetenwatchURL = "abgeordnetenwatch_url"
        case firstName = "first_name"
        case lastName = "last_name"
        case birthName = "birth_name"
        case sex = "sex"
        case yearOfBirth = "year_of_birth"
        case party = "party"
        case partyPast = "party_past"
        case education = "education"
        case residence = "residence"
        case occupation = "occupation"
        case statisticQuestions = "statistic_questions"
        case statisticQuestionsAnswered = "statistic_questions_answered"
        case qidWikidata = "qid_wikidata"
        case fieldTitle = "field_title"
    }
}

// MARK: - Party
struct Party1: Codable {
    let id: Int
    let entityType, label: String
    let apiURL: String

    enum CodingKeys: String, CodingKey {
        case id
        case entityType = "entity_type"
        case label
        case apiURL = "api_url"
    }
}

我正在尝试使用 Json 解析器从该站点linkk收集数据。 我使用了教程推荐的quicktype

删除case party = "party"

或打开

// let party: Referenz -> Party? 线

暂无
暂无

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

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