0

私は次のように持ってJSONいます

{
    "code":0,
    "response":{
        "Cirqit":{
            "Cirqit":{...},
            "Owner":{...},
            "CirqitMembers":[
                {
                    "User":{...},
                    "CirqitMember":{...}
                },
                {
                    "User":{...},
                    "CirqitMember":{...}
                }
            ]
        }
    }
}

私のマッピングコードは以下の通りです:

   //User mapping
    RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:apiInterface.managedObjectStore];
    NSDictionary *userMappingDict = @{@"id": @"id",@"firstname": @"firstname"};
    [userMapping addAttributeMappingsFromDictionary:userMappingDict];

    //Member Status Mapping
    RKEntityMapping *membStatusMapping = [RKEntityMapping mappingForEntityForName:@"MemberStatusInfo" inManagedObjectStore:apiInterface.managedObjectStore];
    NSDictionary *membStatusMappingDict = @{@"id": @"id",@"user_id": @"user_id"};    [membStatusMapping addAttributeMappingsFromDictionary:membStatusMappingDict];

    //Cirqit Member Mapping
    RKEntityMapping *membMapping = [RKEntityMapping mappingForEntityForName:@"CirqitMember" inManagedObjectStore:apiInterface.managedObjectStore];
    NSDictionary *membMappingDict = @{ @"CirqitMember.id":@"id" };
    [membMapping addAttributeMappingsFromDictionary:membMappingDict];
    [membMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"response.Cirqit.CirqitMembers.User" toKeyPath:@"memberStatus" withMapping:userMapping]];
    [membMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"response.Cirqit.CirqitMembers.CirqitMember" toKeyPath:@"memberDetails" withMapping:membStatusMapping]];
    membMapping.identificationAttributes = @[@"id"];

    //Cirqit Mapping
    RKEntityMapping *cirqitMapping = [RKEntityMapping mappingForEntityForName:@"Cirqit" inManagedObjectStore:apiInterface.managedObjectStore];
    NSDictionary *cirqitMappingDict = @{   @"response.Cirqit.Cirqit.id":@"id",
                                 @"response.Cirqit.Cirqit.allow_invite": @"allow_invite"};    
    [cirqitMapping addAttributeMappingsFromDictionary:cirqitMappingDict];
    [cirqitMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"response.Cirqit.CirqitMembers" toKeyPath:@"cirqitMembers" withMapping:membMapping]];
    cirqitMapping.identificationAttributes = @[@"id"];

    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:cirqitMapping pathPattern:nil keyPath:nil statusCodes:statusCodes];
    operation = [apiInterface getOperationWithRequest:request forResponseDescriptors:@[responseDescriptor]];
    [operation start];

ここで membMapping,cirqitMapping は正常に動作します。しかし、membStatusMapping、userMapping は機能していません。実際にはマッピング エラーはありませんが、マッピングは発生しません。

以下の私の管理対象オブジェクトクラス:

@interface CirqitMember : NSManagedObject

@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) MemberStatusInfo *memberDetails;
@property (nonatomic, retain) User *memberStatus;

@end
4

1 に答える 1

2

リレーションシップ マッピングを追加する場合、マッピングのキー パスは、ルートに対してではなく、コンテナーに対して相対的である必要があります。現在、次のものがあります。

[membMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"response.Cirqit.CirqitMembers.User" toKeyPath:@"memberStatus" withMapping:userMapping]];
[membMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"response.Cirqit.CirqitMembers.CirqitMember" toKeyPath:@"memberDetails" withMapping:membStatusMapping]];

それを次のように変更します。

[membMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"User" toKeyPath:@"memberStatus" withMapping:userMapping]];
[membMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"CirqitMember" toKeyPath:@"memberDetails" withMapping:membStatusMapping]];

これは、次の場合にも適用されます。

[cirqitMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"response.Cirqit.CirqitMembers" toKeyPath:@"cirqitMembers" withMapping:membMapping]];

しかし、それはおそらくJSONの構造のために機能します...

于 2013-06-25T09:26:54.070 に答える