REST Kit 0.10.0 - POST无效

时间:2013-04-11 03:15:04

标签: iphone ios objective-c json restkit

我正在使用 REST Kit 0.10.0 而我无法执行RKRequestMethodPOST

我的数据库名称是 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添加映射错误:   无法找到keyPath的对象映射:''

这是 Venue

@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 

对此有任何帮助表示赞赏。

感谢。

1 个答案:

答案 0 :(得分:0)

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

将keypath @“venue”更改为其他内容,因为它与您的响应映​​射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];