Objective c 使用两种JSON格式反序列化Mantle对象
有没有一种方法可以使用两个不同的JSON对象构造mantle对象?例如,假设有一个Address类和以下两种JSON格式:Objective c 使用两种JSON格式反序列化Mantle对象,objective-c,json,github-mantle,Objective C,Json,Github Mantle,有没有一种方法可以使用两个不同的JSON对象构造mantle对象?例如,假设有一个Address类和以下两种JSON格式: { "street: "s", "city" : "city", "state" : "state", "zipcode" "12345" } { "street_one: "s1", "street_two: "s2", "apartment" : "apt 1", "city" : "city",
{
"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
}
}
希望执行上述操作,或任何允许有条件映射到对象的操作。Mantle不支持此操作,但您可以使用具有额外street条目的V2子类,或使用协议封装共享行为