This question shows research effort; it is useful and clear
1
This question does not show any research effort; it is unclear or not useful
Bookmark this question.
Show activity on this post.
[Xcode 9,斯威夫特 4]
我测试以下代码:
为什么输出是-1,而不是1?
class A: Codable {
}
class A_a: A {
var a: Int = -1
}
let json = """
{
"a": 1
}
"""
let jsonData = json.data(using: .utf8)!
let obj = try? JSONDecoder().decode(A_a.self, from: jsonData)
obj?.a