2011-10-17 2 views
0

임 : latest_update 필드의 매핑에 문제가 있습니다. JSON 데이터입니다.RestKit - "고급 데이터 개체"의 개체 매핑 문제가 있습니까?

내 웹 서비스에서이 JSON 데이터를 잡 :

{"Places":[ 
    {"place_ID": "7cceedda-ed3a-11e0-a1a8-858e3974979a", 
    "timestamp": "2011-10-02 23:24:42" 
    }, 
    {"place_ID": "7cceedda-ed3a-11e0-a1a8-858e3974933x", 
    "timestamp": "2011-10-02 23:24:42" 
    }, 
    {"latest_update":"2011-10-13 12:16:17"}] 

}

그리고 내가 관리 매핑에 사용하는 코드의 싹둑 :

//Place mapping 
    if (!self.placeManagedObject){ 
     self.placeManagedObject = [RKManagedObjectMapping 
mappingForClass:[Place class]]; 
     self.placeManagedObject.primaryKeyAttribute = @"UUID"; 
     self.placeManagedObject.rootKeyPath = @"places"; 
     [self.placeManagedObject mapKeyPath:@"place_ID" 
toAttribute:@"UUID"]; 
     [self.placeManagedObject mapKeyPath:@"timestamp" 
toAttribute:@"timestamp"]; 
     [self.placeManagedObject mapRelationship:@"PlaceInformation" 
withMapping:self.placeInfoManagedObject]; 
     // Register mapping with the provider - means it will look for 
places in the JSON input 
     [objectManager.mappingProvider 
setMapping:self.placeManagedObject forKeyPath:@"places"]; 
    } 
    //latestDBUpdate timestamp mapping 
    if (!self.latestDBUpdateManagedObject){ 
     self.latestDBUpdateManagedObject = [RKManagedObjectMapping 
mappingForClass:[LatestDBUpdate class]]; 
     self.latestDBUpdateManagedObject.primaryKeyAttribute = 
@"latest_update"; 
     self.latestDBUpdateManagedObject.rootKeyPath = @"places"; 
     [self.latestDBUpdateManagedObject mapKeyPath:@"latest_update" 
toAttribute:@"latest_update"]; 
     // Register mapping with the provider - means it will look for 
places in the JSON input 
     [objectManager.mappingProvider 
setMapping:self.latestDBUpdateManagedObject 
forKeyPath:@"latest_update"]; 
    } 

RestKit 장소 객체를 매핑합니다 올바른 예 : { "place_ID": "7cceedda-ed3a-11e0-a1a8-858e3974979a", "타임 스탬프": "2011-10-02 23:24:42"장소 객체로} ... , 하지만 latest_updateLatestDBUpdate 클래스 개체로 매핑되지 않은, 그리고 난 어떤 방법으로이 동작하지 않습니다.

검색과 시도로 인해 해결책을 찾을 수 없기 때문에 누군가에게 답변을 보내주기를 바랍니다. 고맙습니다 토마스

답변

2

그래서 나는 그것을 마침내 발견했습니다. 기본적으로 몇 가지 작은 개조하면 되겠 어, 내 대신 오류의 몇 가지 : -/

그래서 내가이 형식으로 내 웹 서비스에서 JSON 출력을 변경 :

{"Places":[ 
{"place_ID": "7cceedda-ed3a-11e0-a1a8-858e3974979a", 
"timestamp": "2011-10-02 23:24:42" 
}, 
{"place_ID": "7cceedda-ed3a-11e0-a1a8-858e3974933x", 
"timestamp": "2011-10-02 23:24:42" 
}], 
"Timestamps":[ 
{"latest_update":"2011-10-13 12:16:17"}] 

나는 매핑 OG에 오류가 발생했습니다 타임 스탬프 -> latest_update, 그래서 fixxed :

//latestDBUpdate timestamp mapping 
if (!self.latestDBUpdateManagedObject){ 
    self.latestDBUpdateManagedObject = [RKManagedObjectMapping mappingForClass:[LatestDBUpdate class]]; 
    self.latestDBUpdateManagedObject.primaryKeyAttribute = @"latest_update"; 
    self.latestDBUpdateManagedObject.rootKeyPath = @"Timestamps"; 
    [self.latestDBUpdateManagedObject mapKeyPath:@"latest_update" toAttribute:@"latest_update"]; 

    // Register mapping with the provider - means it will look for the keyword Timestamps in the JSON input 
    [self.objectManager.mappingProvider setMapping:self.latestDBUpdateManagedObject forKeyPath:@"Timestamps"]; 

그리고 나서 내 get 메소드에 중대한 오류가있었습니다. 기본적으로 RestKit에 응답은 내 장소 매핑에 의해서만 매핑되어야하므로 다른 키워드에 대해서는 JSON 입력의 다른 데이터를 모두 확인하지 말아야한다고 말했습니다. 차이점을 보여주기 위해 내가 사용한 두 가지 방법을 모두 제시했습니다. 첫 번째는 지정된 매핑 방식으로지도하며, 두 번째는 모든 registred 매핑 기법으로 확인합니다 :

GET 방법 번호 1 : (! 즉, 위의 상황에서 작동하지 않습니다)

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:gPlaceListBaseUrl objectMapping:self.placeManagedObject delegate:self]; 

GET 방법 numer에 2 : (여기에 모든 매핑 방식이 선택되어 두 장소 객체 내 LatestDBUpdate 객체뿐만 아니라 매핑됩니다!)

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:gPlaceListBaseUrl delegate:self]; 

잘하면 사람이 언젠가는해야 할 수도 있습니다 : -D

,536을

토마스