Pergunta

I call an api which can have differents interface for the same value "id" : "id", "_id" or "pId".

But currently, it's works for only the first : @"id": @"_id". the other are ignored.

JSON

 object:{ "pId" : 192039,
         "name" : "test}

IOS WHICH WORKS: self.id = 192039

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{
             @"id": @"pId",
             @"id": @"_id",
             @"id": @"id",
             @"title": @"name",
            };
}

IOS WHICH NOT WORKS: self.id =

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{

             @"id": @"_id",
             @"id": @"id",
             @"id": @"pId",
             @"title": @"name",
            };
}

EDIT

Keys in a dictionary must be unique....

The only solution I found is to create 3 differents properties and override setters like that:

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{
             @"pId": @"pId",
             @"id2": @"_id",
             @"id": @"id",
             @"title": @"name",
            };
}

- (void) setPid:(NSString *)pId
{
    _id = pId;
}

- (void) setId2:(NSString *)id2
{
    _id = id2;
}
Foi útil?

Solução 2

Keys in a dictionary must be unique....

The only solution I found is to create 3 differents properties and override setters like that:

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{
             @"pId": @"pId",
             @"id2": @"_id",
             @"id": @"id",
             @"title": @"name",
            };
}

- (void) setPid:(NSString *)pId
{
    _id = pId;
}

- (void) setId2:(NSString *)id2
{
    _id = id2;
}

Outras dicas

you cannot repeat te key

@{key:value,...}

you can try other thing like this

return @{
     @"id" : @[@"_id",@"id",@"pId"],
     @"title" : @"name"
   };

or adding a prefix to @"id" keys like @"id1

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top