0

swift 4 Decodable 协议如何与“ - ”字母一起使用?例如:

[{
    "trigger": {
        "url-filter": "webkit.org",
        "resource-type": ["image"]
 },
    "action": {
        "selector": "#logo",
        "type": "block"
    }
}]

在我的 Swift 课程中:

struct blockerJson : Decodable {
    let action : action
    let trigger : trigger

    struct action : Decodable {
        let selector : String
        let type : String
    }

    struct trigger : Decodable {
        let urlFilter : String
        let resourceType : String
    }
}

不知道怎么改class,但是json不能改...

4

1 回答 1

1

此代码解析触发块

struct Trigger: Decodable {
    var urlFilter: String
    var resourceType: [String]

enum CodingKeys: String, CodingKey {
        case urlFilter = "url-filter"
        case resourceType = "resource-type"
    }
}
于 2017-12-26T06:59:39.393 回答