2017-03-29 9 views
0

임 RKEntityMapping와 RestKit를 사용하려고 응답 설명자에 문제가 RKEntityMapping ( 도움말을 여기RestKit,

NSURL *baseURL = [NSURL URLWithString:@"http://api.mymemory.translated.net"]; 

RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL]; 


// Initialize managed object model from bundle 
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil]; 
// Initialize managed object store 
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel]; 
objectManager.managedObjectStore = managedObjectStore; 


// Complete Core Data stack initialization 
[managedObjectStore createPersistentStoreCoordinator]; 
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"MyArticlesDB.sqlite"]; 
NSString *seedPath = [[NSBundle mainBundle] pathForResource:@"RKSeedDatabase" ofType:@"sqlite"]; 
NSError *error; 

NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:seedPath withConfiguration:nil options:nil error:&error]; 
NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error); 

// Create the managed object contexts 
[managedObjectStore createManagedObjectContexts]; 

// Configure a managed object cache to ensure we do not create duplicate objects 
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext]; 

RKEntityMapping *matchMapping = [RKEntityMapping mappingForEntityForName:@"Match" inManagedObjectStore:managedObjectStore]; 
[matchMapping addAttributeMappingsFromDictionary:@{@"id" :@"id", 
                @"segment" :@"segment", 
                @"trnaslation" :@"translation", 
                @"quality"  :@"quality", 
                @"reference"  :@"reference", 
                @"usage-count" :@"usage_count", 
                @"subject"  :@"subject", 
                @"created-by" :@"MateCat", 
                @"last-updated-by" :@"last_updated_by", 
                @"create-date"  :@"create_date", 
                @"last-update-date" :@"last_update_date", 
                @"tm_properties"  :@"tm_properties", 
                @"match"   :@"match"}]; 


RKEntityMapping *translationMapping = [RKEntityMapping mappingForEntityForName:@"Translation" inManagedObjectStore:managedObjectStore]; 
[translationMapping addAttributeMappingsFromDictionary:@{@"responseData.translatedText"  :@"translatedText", 
                 @"responseData.match"    :@"match", 
                 @"responseDetails"     :@"responseDetails", 
                 @"responseStatus"     :@"responseStatus", 
                 @"responseId"      :@"responseId"}]; 









     RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:translationMapping method:RKRequestMethodGET pathPattern:@"/" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 
[objectManager addResponseDescriptor:responseDescriptor]; 

JSON : http://api.mymemory.translated.net/get?q=Hello%20World!&langpair=en%7Cru

오류 :

오류 도메인 = 조직. restkit.RestKit.ErrorDomain Code = 1001 "로드 된 응답과 일치하는 응답 설명자가 없습니다."UserInfo = {NSLocalizedFailureReason = URL에서 200 응답이로드되었습니다. 'NSErrorFailingURLStringKey = http://api.mymemory.translated.net/get?q=Hello%20World!&langpair=en%7Cru, NSErrorFailingURLKey = http://api.mymemory.translated.net/get?q=Hello%20World!&langpair=en%7Cru, NSUnderlyingError = 0x1700562f0 {오류 도메인 = org.restkit.RestKit.ErrorDomain Code = 1001 "키에서 표시 가능한 객체 표현이 발견되지 않았습니다 () 경로를 검색했습니다. "UserInfo = {NSLocalizedDescription = 검색된 키 경로에서 표시 가능한 객체 표현이 없습니다., NSLocalizedFailureReason = 매핑 작업에서 검색된 키 경로에서 중첩 된 객체 표현을 찾을 수 없습니다 : 맵퍼에 입력 된 표현이 발견되었습니다 일치, responderId, responseData, responseDetails, responseStatus 이것은 매핑에 대한 키 경로를 잘못 구성했음을 나타냅니다. keyPath = null, DetailedErrors = ( )}}, keyPath = null, NSLocaliz edDescription =로드 된 응답과 일치하는 응답 설명자가 없습니다.}

답변

0

관계를 추가하는 것을 잊었습니다. 이것은 나를 도왔다.

RKRelationshipMapping *res = [RKRelationshipMapping relationshipMappingFromKeyPath:@"responseData" toKeyPath:@"responseData" withMapping:responseMapping]; 

RKRelationshipMapping *matchRelation = [RKRelationshipMapping relationshipMappingFromKeyPath:@"matches" toKeyPath:@"matches" withMapping:matchMapping]; 


[globalMappig addPropertyMapping:matchRelation]; 
[globalMappig addPropertyMapping:responseRelation];