SWIFT 解析模型 JSON

SWIFT model for parsing JSON

我需要解析JSON的数据。为此,我将使用协议 Codable。 收到的 json 看起来像这样(这是我感兴趣的部分):

(
    {
        description = mySecondGist;
        files =         {
            "gistfile1.txt" =             {
                filename = "gistfile1.txt";
                language = Text;
                "raw_url" = "https://gist.githubusercontent.com/VladimirKhuraskin/9ca2362c09cebcc16bd74f51f267231a/raw/74caacd3ad3eedb369a07b926327d2ef37e3eefc/gistfile1.txt";
                size = 17;
                type = "text/plain";
            };
        };
    }
)

我做了这个模型:

struct Gists: Codable {
    var description: String?
    var files: DetailGist?

    private enum CodingKeys: String, CodingKey {
        case description
        case files
    }
}

struct DetailGist: Codable {
    var filename: String?
    var rawUrl: String?

    private enum FileCodingKeys: String, CodingKey {
        case filename
        case rawUrl = "raw_url"
    }
}

这是正确的模型吗?还是需要最终确定?我对

感到困惑
files =         {
            "gistfile1.txt" = 

谢谢!

不,文件是字典。这就是 JSON 中的 {} 标记的意思。您希望 Gists 模型是

var files: [String: DetailGist]?