【问题标题】:RestKit and Restlet JSON key-valueRestKit 和 Restlet JSON 键值
【发布时间】:2013-05-06 11:49:02
【问题描述】:

在RestKit 中用于将一个类映射到我们使用的JSON 键值,

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

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

有没有类似android restlet?的iOS restkit更简单的方法

提前致谢。

【问题讨论】:

    标签: ios json restkit restlet


    【解决方案1】:

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

    REFER HERE

    【讨论】:

      猜你喜欢
      • 2015-03-11
      • 1970-01-01
      • 2013-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多