使用 Swift 解析 @odata 值时出现问题

Issue with parsing @odata values using Swift

我的服务响应如下:

{
"@odata.context" = "https://xxx-d.www.com/odata/$metadata#Members";
"@odata.count" = 1;
 value = ({
        email = "Suamasu@xxx.com";
        memberType = User;
        name = "Suse";
        title = "Manager";
   });
}

我能够解码使用 Decodable swift 类型的 value,但是我需要解码 "@odata.count" 值来自回应。

struct Members: Decodable {
    let value: [Member]
}

struct Member: Decodable {
    let name: String?
    let email: String
    let memberType: String?
    let title: String?
}

能不能试试给会员添加编码键?

struct Members: Decodable {
    let context: String
    let count: Int
    let value: [Member]

    enum CodingKeys: String, CodingKey {
        case context = "@odata.context"
        case count = "@odata.count"
        case value 
    }
}

更多信息:https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types