我需要将类的所有键及其值转换为小写。例如,
class Person : Encodable {
var firstName: String
var lastName: String
var city: String
}
var person = Person(firstName: "David", lastName: "Gill", city:
"Toronto")
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToLowerCase
let encoded = try encoder.encode(person)
print(String(decoding: encoded, as: UTF8.self))
convertToLowerCase
我在扩展中添加的JSONEncoder.KeyEncodingStrategy
将键转换为小写的方法在哪里。
它打印 -{"city":"Toronto","firstname":"David","lastname":"Gill"}
我需要打印的是 -{"city":"toronto","firstname":"david","lastname":"gill"}
有人可以在这里帮忙吗?