我有一个这样的请求对象:
@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 的一些关键步骤?