簡體   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