2013-01-04 2 views
4

나는 Client와 비슷한 모양의 객체를 가지고 있습니다.RestKit 0.20 중첩 된 배열이있는 POST JSON

@interface Client : NSManagedObject 
    @property (nonatomic, retain) NSString * firstName; 
    @property (nonatomic, retain) NSString * middleName; 
    @property (nonatomic, retain) NSString * lastName; 
    @property (nonatomic, retain) Styles *clientStyles; 
@end 

스타일은 클라이언트 아래의 중첩 된 개체입니다. 그것은 일대일 관계입니다. 이것이 JSON의 서버에서 내려 오면 다음과 같이 보입니다.

{ 
    "firstName": "", 
    "middleName": "", 
    "lastName": "", 
    "firstStyle": { 
     "styleId": 4, 
     "name": "", 
     "description": "", 
     "stylingTime": "55 min", 
     "stylingProductUsage": "A lot", 
     "chemicals": "LOTS O'GEL", 
     "deleted": false, 
     "modifiedOn": 1357161168830 
    } 
} 

모든 것이 멋진 단일 개체에 있습니다. 나는 이것을 아래로 당겨 내 물건에 아무 문제없이지도 할 수있다. 이 문제는 서버로 돌려 보내야 할 때 발생합니다. 이 형식이어야합니다.

{ 
    "firstName": "", 
    "middleName": "", 
    "lastName": "", 
    "styles": [ 
     { 
      "styleId": 4, 
      "name": "", 
      "description": "", 
      "stylingTime": "55 min", 
      "stylingProductUsage": "A lot", 
      "chemicals": "LOTS O'GEL", 
      "deleted": false, 
      "modifiedOn": 1357161168830 
     }] 

} 반환 매핑보다는 일대일되고, 배열 안에 앉아 스타일 엔티티를 가지고 있기 때문에 매우 문제가

. 지금까지 나는 그것이 하나 개의 값으로 스타일 객체의 배열을 반환합니다 그래서 도대체 내가 매핑을 만들려면 어떻게해야합니까 내 RKRequestDescriptor

RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; 
[requestMapping addAttributeMappingsFromDictionary:@{ 
    @"firstName": @"firstName", 
    @"middleName": @"middleName", 
    @"lastName": @"lastName", 
}]; 
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping 
                       objectClass:[Client class] 
                       rootKeyPath:nil]; 

으로 이것을 가지고 ???

답변

0

추측하지만, 매핑은 같은 것을 할 수없는, 꽤 똑똑 :

RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; 
[requestMapping addAttributeMappingsFromDictionary:@{ 
    @"firstName": @"firstName", 
    @"middleName": @"middleName", 
    @"lastName": @"lastName", 
}]; 

RKObjectMapping *stylesMappingDescription = [RKObjectMapping requestMapping]; 
[requestMapping addAttributeMappingsFromDictionary:@{ 
    @"properties": @"here" 
}]; 

[requestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"styles.0" toKeyPath:@"styles" withMapping:stylesMappingDescription]]; 

RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor  requestDescriptorWithMapping:requestMapping 
                       objectClass:[Client class] 
                      rootKeyPath:nil]; 

이 (fromKeyPath로 styles.0주의를)

관련 문제