0
我有這樣一個請求對象,以便:使用RestKit的RKObjectMapping和RKObjectSerializer爲RKClient之後的參數時,遇到了一個錯誤
@interface MyUpdate
@property (nonatomic, copy) NSString* name;
@property (nonatomic, assign) int value;
@end
@interface MyRequest
@property (nonatomic, assign) int index;
@property (nonatomic, retain) MyUpdate* update;
@end
我使用RKObjectMapping和RKObjectSerializer創建JSON字符串,並以POST使用它:
RKObjectMapping* updateMapping = [RKObjectMapping mappingForClass:[MyUpdate class]];
[updateMapping mapForKeyPath:@"name" toAttribute:@"Name"];
[updateMapping mapForKeyPath:@"value" toAttribute:@"Value"];
RKObjectMapping* requestMapping = [RKObjectMapping mappingForClass:[MyRequest class]];
[requestMapping mapForKeyPath:@"index" toAttribute:@"Index"];
[requestMapping mapKeyPath:@"update" toRelationship:@"Update" withMapping:updateMapping];
RKObjectSerializer* serializer = [RKObjectSerializer serializerWithObject:request mapping:requestMapping];
[[RKClient sharedClient] post:requestPath params:[serializer serializationForMIMEType:RKMIMETypeJSON error:nil] delegate:self];
request
是我MyRequest
類的一個實例。 requestPath
只是一個NSString
。
我不斷收到這個錯誤,說一個關鍵是無效的MyUpdate,即使我已經映射。我是否錯過了使用RKObjectMapping的關鍵步驟?