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



我的服务响应如下:

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

我可以使用可解码的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?
}

您可以尝试为Members添加编码键吗?

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

相关内容

  • 没有找到相关文章

最新更新