私は次のようなリクエストオブジェクトを持っています:
@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 を使用していくつかの重要なステップを見逃していますか?