有没有办法使用两个不同的 JSON 对象来构造一个地幔对象?例如,假设有一个 Address 类和以下两种 JSON 格式:
{
"street: "s",
"city" : "city",
"state" : "state",
"zipcode" "12345"
}
{
"street_one: "s1",
"street_two: "s2",
"apartment" : "apt 1",
"city" : "city",
"state" : "state",
"zip" "12345"
}
[MTLJSONAdapter modelOfClass:[Address class] fromJSONDictionary:JSONDictionary error:&error];
MTLJSONAdapter 中是否有某个地方可以识别两种格式并根据它们分配或序列化属性?
+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
if (isJsonV2) {
// do new mapping
}
else {
// do original mapping
}
}
希望做类似上面的事情,或者任何允许有条件地映射到对象的事情。