0

为了RestKit将类映射到JSON我们使用的键值,

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

但是在android中,如果使用restlet,我们只需要@JsonProperty("PrimaryKey"),在类中声明变量时添加即可。键值映射就完成了。

iOS restkit 是否有更简单的方法类似于android restlet?

提前致谢。

4

1 回答 1

0

你可以在ios中这样做

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

// 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" ]];

参考这里

于 2013-05-06T12:01:03.050 回答