我正在尝试解码JSON,该JSON包含使用句点/点前缀(.ends
和.starts
)编写的两个密钥。但是解码代码会引发错误。
我的结构如下:
struct APICallResponse: Codable {
var user: String
var ends: String
var starts: String
enum CodingKeys: String, CodingKey {
case user
case ends = ".ends"
case starts = ".starts"
}
}
我的解码代码:
do {
let decoder = JSONDecoder()
let dataObject = try decoder.decode(APICallResponse.self, from: data)
} catch {
print("Error"
}
我的JSON:
{
"user": "Mark",
".ends": "2018-10-26T11:30:46.5889685+05:30",
".starts": "2018-10-26T11:33:46.5889685+05:30",
}
如何处理点前缀?