繁体   English   中英

RestKit和Restlet JSON键值

[英]RestKit and Restlet JSON key-value

在用于将类映射到JSON键值的RestKit中,

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?更简单的方法android restlet?

提前致谢。

您可以在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" ]];

在这里参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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