2013-01-10 1 views
0

JSON을 RestKit 응용 프로그램에 매핑하는 데 어려움이 있습니다. 코어 데이터에도 저장하고 싶습니다. 따라서 이미지에 대한 두 개의 링크가 있습니다. 첫 번째 이미지, 내 JSON의 모습.Restkit에서 JSON을 어려운 시간에 매핑

IMAGE1

두 번째 이미지는 내 핵심 데이터베이스가 보이는 방법이다.

IMAGE2

이제 제 I은 코어 데이터 층없이 적용했다. 따라서 데이터를 읽고 작업하십시오. 그 시점에서 모든 것이 효과가있었습니다. 그러나 핵심 데이터를 가지고 이와 같은 매핑 오류가 발생했습니다.

LOG는

2013-01-10 10:46:02.663 Offitel2[27978:6813] D restkit.object_mapping:RKMappingOperation.m:635 Did not find mappable relationship value keyPath 'Person' 
2013-01-10 10:46:02.664 Offitel2[27978:6813] D restkit.object_mapping:RKMappingOperation.m:635 Did not find mappable relationship value keyPath 'Function' 
2013-01-10 10:46:02.664 Offitel2[27978:6813] D restkit.object_mapping:RKMappingOperation.m:635 Did not find mappable relationship value keyPath 'Department' 
2013-01-10 10:46:02.665 Offitel2[27978:6813] D restkit.object_mapping:RKMappingOperation.m:635 Did not find mappable relationship value keyPath 'Company' 

2013-01-10 10:46:02.672 Offitel2[27978:164f] W restkit.core_data:RKManagedObjectRequestOperation.m:555 Caught undefined key exception for keyPath 'user' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings. 
2013-01-10 10:46:02.673 Offitel2[27978:164f] W restkit.core_data:RKManagedObjectRequestOperation.m:555 Caught undefined key exception for keyPath 'function' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings. 
2013-01-10 10:46:02.674 Offitel2[27978:164f] W restkit.core_data:RKManagedObjectRequestOperation.m:555 Caught undefined key exception for keyPath 'department' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings. 
2013-01-10 10:46:02.676 Offitel2[27978:164f] W restkit.core_data:RKManagedObjectRequestOperation.m:555 Caught undefined key exception for keyPath 'company' in mapping result: This likely indicates an ambiguous keyPath is used across response descriptor or dynamic mappings. 

이것은 내가 코드에서 나의 관계 매핑을 수행하는 방법이다.

RKRelationshipMapping* relationUserMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Person"toKeyPath:@"user"withMapping:personMapping]; 
    RKRelationshipMapping* relationFunctionMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Function"toKeyPath:@"function"withMapping:functionMapping]; 
    RKRelationshipMapping* relationDepartmentMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Department"toKeyPath:@"department"withMapping:departmentMapping]; 
    RKRelationshipMapping* relationCompanyMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Company"toKeyPath:@"company"withMapping:companyMapping]; 
     NSLog(@"till here7"); 
    [dataMapping addPropertyMapping:relationUserMapping]; 
    [dataMapping addPropertyMapping:relationFunctionMapping]; 
    [dataMapping addPropertyMapping:relationDepartmentMapping]; 
    [dataMapping addPropertyMapping:relationCompanyMapping]; 

아무도 도와 주실 수 없습니까? 나는 핵심 데이터의 매핑에 대해 며칠 동안 고민하고있다.

감사합니다.

답변

1

이것을 위해 RKManagedObjectMapping을 사용해보세요. 다음과 같이 RKManagedObjectMapping 개체를 구성합니다.

RKURL * baseURL = [RKURL URLWithBaseURLString : serverUrl];

RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL]; 

    objectManager.client.baseURL = baseURL; 

    objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES; 

    objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL]; 

    RKManagedObjectStore *objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:DB_NAME]; 

    objectManager.objectStore = objectStore; 

그런 다음 각 데이터 클래스와 relationshipShip에 대한 매핑을 설정해야합니다. 나는 여기서 내가 사용한 예를 하나 넣어 보려고한다. 여기

- (void)setReservationMapping:(RKManagedObjectMapping *)object 
    { 
    [object mapKeyPathsToAttributes: 
     @"id", @"reservationId", 
     @"comment", @"comment", 
     @"date", @"date", 
     @"email", @"email",nil]; 
    } 

를 다음과 같이 내 setReservationMapping이

/** specify the base mapping of reservation class */ 
    RKManagedObjectMapping *getReservationMapping = [RKManagedObjectMapping mappingForClass:[Reservation class] inManagedObjectStore:objectManager.objectStore]; 
    /** generate mapping for Reservation class */ 
    [self setReservationMapping:getReservationMapping]; 
    [email protected]"reservationId"; 
    [objectManager.mappingProvider setMapping:getReservationMapping forKeyPath:@""]; 


    /** specify the base mapping of ReservationsType class */ 
    RKManagedObjectMapping *resTypeMapping = [RKManagedObjectMapping mappingForClass:[ReservationsType class] inManagedObjectStore:objectManager.objectStore]; 
    /** generate mapping for ReservationsType class */ 
    [self setReservationsTypeMapping:resTypeMapping]; 
    [email protected]"reservationTypeId"; 
    [getReservationMapping mapRelationship:@"reservationsType" withMapping:resTypeMapping]; 
    [objectManager.mappingProvider setMapping:resTypeMapping forKeyPath:@".reservationsType"]; 

내 JSON의 샘플입니다. 저의 예약 노드에는 식별자가 없으므로 keyPath를 부여했습니다 : @ "".

 [{ 
    id: 5644, 
    comment: "", 
    email: "[email protected]", 
    firstName: "Danny", 
    reservationsType: 
{ 
    id: 1, 
    name: "Reservation", 
    } 
    }] 

희망이 도움이 될 것입니다.

관련 문제