CodableWrapper
CodableWrapper copied to clipboard
version:0.3.3 时奔溃。希望能找找原因。
import CodableWrapper
struct LocationModel: Codable {
@Codec("Id")
var id: String? = nil
@Codec("Value")
var value: String? = nil
@Codec("Children")
var child: [LocationModel]? = nil
}
Test:
let jsonString2 =
"[{\"Value\":null,\"Label\":\"State/Province\",\"Id\":\"a0Mp0000007ANEoEAO\",\"Children\":[{\"Value\":\"Bangkok\",\"Label\":\"City\",\"Id\":\"a0Mp0000007ANe7EAG\",\"Children\":[{\"Value\":\"Bang Kapi\",\"Label\":\"District\",\"Id\":\"a0Mp0000007ANeCEAW\",\"Children\":null}]}]}]".data(using: .utf8)!
let decoder = JSONDecoder()
let model = try! decoder.decode([LocationModel].self, from: jsonString2)
logInfo("json = \(model.toJSONString())")