Json 有没有办法将数字作为变量';她叫什么名字?
我有一个JSON响应,其中JSON的键值是“0”。我正在使用Swift的Codable协议来解析我的JSON。是否有任何方法可以将“0”作为变量名或其他解决方法?我知道SwiftyJSON用于解析JSON,但我更喜欢使用本地swift协议。 如果“0”键是常量,则可以使用Json 有没有办法将数字作为变量';她叫什么名字?,json,ios13,swift4.2,Json,Ios13,Swift4.2,我有一个JSON响应,其中JSON的键值是“0”。我正在使用Swift的Codable协议来解析我的JSON。是否有任何方法可以将“0”作为变量名或其他解决方法?我知道SwiftyJSON用于解析JSON,但我更喜欢使用本地swift协议。 如果“0”键是常量,则可以使用编码键将其映射到有效的属性名称,如下所示: struct Response: Codable { let success: Bool let data: DataClass let error, mess
编码键将其映射到有效的属性名称,如下所示:
struct Response: Codable {
let success: Bool
let data: DataClass
let error, message: String
}
struct ZeroKeyType: Codable {
// properties go here
}
struct DataClass: Codable {
let the0: ZeroKeyType
let searchField: [String]
enum CodingKeys: String, CodingKey {
case the0 = "0"
case searchField
}
}