RestKit映射:如何映射多个数组对象

时间:2016-02-02 07:56:08

标签: ios iphone restkit

我正在尝试映射但显示错误

发现输入到映射器的表示包含以下关键路径的嵌套对象表示:块,描述,id,名称

这可能表示您错误配置了映射的关键路径。

keyPath = null,DetailedErrors =( )},keyPath = null,NSLocalizedDescription =没有响应描述符匹配加载的响应。}

我的json回复是 enter image description here

我的代码是:

@interface PropertyBlock : NSObject

@property (nonatomic, retain) NSString* id;
@property (nonatomic, retain) NSString* name;
@property (strong, nonatomic) NSString* description;
@property (nonatomic, retain) Blocks * blocks;

-----------
@interface Blocks : NSObject

@property (nonatomic, retain) NSString* id;
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) NSString* url;
@property (nonatomic, retain) Rooms * rooms;

-----------
@interface Rooms : NSObject

@property (nonatomic, retain) NSString* id;
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) Tenants* tenants;

-----------
@interface Tenants : NSObject

@property (nonatomic, retain) NSString* id;
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) Payments* payments;

-----------
@interface Payments : NSObject

@property (nonatomic, retain) NSString* id;
@property (nonatomic, retain) NSString* amount;
@property (nonatomic, retain) NSString* amount_type;
@property (nonatomic, retain) NSString* discount;
@property (nonatomic, retain) NSString* receipt_no;
@property (nonatomic, retain) NSString* created_at;

 //Mapping Code

 RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];


    RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[PropertyBlock class]];
    [venueMapping addAttributeMappingsFromArray:@[@"id",@"name",@"description"]];


    RKObjectMapping *blockMapping = [RKObjectMapping mappingForClass:[Blocks class]];
    [blockMapping addAttributeMappingsFromArray:@[@"id", @"name", @"url"]];
    RKRelationshipMapping *relation = [RKRelationshipMapping relationshipMappingFromKeyPath:@"blocks" toKeyPath:@"blocks" withMapping:blockMapping];
    [venueMapping addPropertyMapping:relation];



    RKObjectMapping *roomMapping = [RKObjectMapping mappingForClass:[Rooms class]];
    [roomMapping addAttributeMappingsFromArray:@[@"id", @"name"]];
    RKRelationshipMapping *roomrelation = [RKRelationshipMapping relationshipMappingFromKeyPath:@"rooms" toKeyPath:@"rooms" withMapping:roomMapping];
    [blockMapping addPropertyMapping:roomrelation];




    RKObjectMapping *tenantsMapping = [RKObjectMapping mappingForClass:[Tenants class]];
    [tenantsMapping addAttributeMappingsFromArray:@[@"id", @"name"]];
    RKRelationshipMapping *tenantRelation = [RKRelationshipMapping relationshipMappingFromKeyPath:@"payments" toKeyPath:@"payments" withMapping:tenantsMapping];
    [roomMapping addPropertyMapping:tenantRelation];



    RKObjectMapping *paymentMapping = [RKObjectMapping mappingForClass:[Payments class]];
    [paymentMapping addAttributeMappingsFromArray:@[@"id", @"amount",@"amount_type",@"discount",@"receipt_no",@"created_at"]];
    RKRelationshipMapping *paymentRelation = [RKRelationshipMapping relationshipMappingFromKeyPath:@"payments" toKeyPath:@"payments" withMapping:tenantsMapping];
    [tenantsMapping addPropertyMapping:paymentRelation];

0 个答案:

没有答案