I have below code to test Codable
protocol and JSONDecoder
.
import UIKit
class ClassA: Codable {
var age: Int = 1
}
class ClassB: Codable {
var ageInfo: ClassA?
var name: String
}
let json4 = """
{
"ageInfo": {},
"name": "Jack"
}
""".data(using: .utf8)!
do {
let d = try JSONDecoder().decode(ClassB.self, from: json4)
} catch let err {
print(err)
}
My question is, why json4 can't be decode? or how I can decode json4?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…