2013-04-11 93 views
3

我正在使用REST工具包0.10.0,我無法執行RKRequestMethodPOSTREST工具包0.10.0 - POST不工作

我的數據庫名稱是dbo.Patients和表名稱是患者

它包含3列,比如ID,Name,Address

這裏是我的代碼,

[[RKClient sharedClient] get:@"/Patient" delegate:self]; 
RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Venue class]]; 
RKURL *baseURL = [RKURL URLWithBaseURLString:@"http://175.78.1.4/MyAppTestData/MyAppDataService.svc"]; 

RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL]; 
objectManager.client.baseURL = baseURL; 
[venueMapping mapKeyPathsToAttributes:@"ID",@"Id",@"Name",@"name",@"Address",@"midname",nil]; 

[objectManager.mappingProvider setMapping:venueMapping forKeyPath:@"value"]; 

RKObjectMapping* venueMappingS = [RKObjectMapping mappingForClass:[Venue class]]; 
venueMappingS.setDefaultValueForMissingAttributes = YES; 

[[RKClient sharedClient] setUsername:@"sa"]; 
[[RKClient sharedClient] setPassword:@"123"]; 

RKObjectRouter *router = [[RKObjectRouter alloc] init]; 

[router routeClass:[Venue class] toResourcePath:@"/Patient" forMethod:RKRequestMethodPOST]; 

[[[RKObjectManager sharedManager] mappingProvider] setMapping:venueMappingS forKeyPath:@"value"]; 

[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:[venueMappingS inverseMapping] forClass:[Venue class]]; 
[RKObjectManager sharedManager].router = router; 
[RKObjectManager sharedManager].serializationMIMEType = RKMIMETypeJSON; 
[RKObjectManager sharedManager].acceptMIMEType = RKMIMETypeJSON; 


Venue* venue = [[Venue alloc] init]; 
venue.Id = 4; 
venue.name = @"User1"; 
venue.midname = @"Chicago"; 

[[RKObjectManager sharedManager] postObject:venue delegate:self]; 

目前它顯示了一個錯誤的

W restkit.object_mapping:RKObjectMapper.m:81 Adding mapping error: Could not find an object mapping for keyPath: ''

這裏是我的地點

@interface Venue : NSObject 

@property (strong, nonatomic) NSString *uri; 
@property (strong, nonatomic) NSString *name; 
@property (strong, nonatomic) NSString *midname; 
@property (strong, nonatomic) NSString *lastname; 
@property (strong, nonatomic) NSString *mrn; 
@property (strong, nonatomic) NSString *gender; 
@property (strong, nonatomic) NSString *accession; 
@property (strong, nonatomic) NSDate *dob; 
@property (nonatomic) int Id; 

@end 

對此的任何幫助表示讚賞。

謝謝。

回答

0
[[[RKObjectManager sharedManager] mappingProvider] setMapping:venueMappingS forKeyPath:@"value"]; 

變化的keyPath @ 「場地」 到別的東西,因爲它的響應映射keypath.ex匹配:@ 「reqVenue」

或使用該

RKObjectMapping * entitySerializationMapping = [(RKObjectMapping*) [manager.mappingProvider mappingForKeyPath: @"reqVenue"] inverseMapping]; 

    [manager.mappingProvider setSerializationMapping:entitySerializationMapping 
                forClass:[Venue class]]; 
[[RKObjectManager sharedManager] 
postObject:venue 
mapResponseWith:venueMapping 
delegate:self]; 
+0

檢查後OBJ:joeblow? ?誰:P – 2013-04-11 05:48:52

+0

我已編輯:P ..讓我檢查解決方案.. – 2013-04-11 06:10:50

+0

應用程序崩潰「終止應用程序由於未捕獲的異常'NSInternalInconsistencyException',原因:'您必須提供'Venue'類型的對象的序列化映射」 – 2013-04-11 06:19:55