简体   繁体   中英

RestKit and Restlet JSON key-value

In RestKit for mapping a class to JSON key-value we use,

RKObjectMapping * userMapping = [RKObjectMapping mappingForClass:[User class]];        
[userMapping mapKeyPath:@"PrimaryKey" toAttribute:@"id"];
[[RKObjectManager sharedManager].mappingProvider setMapping:usereMapping forKeyPath:@"clientUser"];

However in android, if restlet is used, we just have to add @JsonProperty("PrimaryKey"), when declaring the variable in the class. And the Key value mapping is done.

Is there a simpler way for iOS restkit similar to android restlet?

Thanks in advance.

You can do it like this in ios

RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[Article class]];
[articleMapping addAttributeMappingsFromDictionary:@{ 
        @"title": @"title",
        @"body": @"body",
        @"author": @"author",
        @"publication_date": @"publicationDate"
    }];

And

// Create our new Author mapping
RKObjectMapping* authorMapping = [RKObjectMapping mappingForClass:[Author class] ];
// NOTE: When your source and destination key paths are symmetrical, you can use addAttributesFromArray: as a shortcut instead of addAttributesFromDictionary:
[authorMapping addAttributeMappingsFromArray:@[ @"name", @"email" ]];

REFER HERE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM