Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用两种JSON格式反序列化Mantle对象_Objective C_Json_Github Mantle - Fatal编程技术网

Objective c 使用两种JSON格式反序列化Mantle对象

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",

有没有一种方法可以使用两个不同的JSON对象构造mantle对象?例如,假设有一个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
    }
}

希望执行上述操作,或任何允许有条件映射到对象的操作。

Mantle不支持此操作,但您可以使用具有额外street条目的V2子类,或使用协议封装共享行为