例如,假设我有这个 json:
{
"media": {
"date": "2016-12-30",
"uniqueID": "eab0923d"
}
我从这个 json 创建一个对象。但请注意,它包含另一个属性,不能使其镜像 json 100%
class Media {
var date: String?
var uniqueID: String?
var anotherProperty: String? // By adding this property, this object does not mirror json 100%
init(jsonDictionary: [String: Any]) {
self.date = jsonDictionary["date"] as! String
self.uniqueID = jsonDictionary["uniqueID"] as! String
// Note: there is nothing in json for `anotherProperty`
}
}
这是好的做法吗?如果有任何潜在的危险,也请告诉我。
最佳答案
我看不出有什么问题。只要您知道自己在做什么。
关于iOS - 不完美地镜像 JSON 是否被认为是不好的做法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41584346/