我在使用RestKit发布json时遇到了问题,但我找不到我做错了什么。 请求json示例是:
{
"Name": "sample string 1",
"Interests": {
"Array": [
1,
2,
3
]
}
}
我的代码:
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromDictionary:@{@"Name": @"Name"}];
RKObjectMapping *interestsMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
RKObjectMapping *interestIDMapping = [RKObjectMapping mappingForClass:[KLInterest class]];
[interestIDMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"InterestID"]];
[interestsMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Array" toKeyPath:@"Array" withMapping:interestIDMapping]];
[requestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Interests" toKeyPath:@"Interests" withMapping:interestsMapping]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[NSMutableDictionary class] rootKeyPath:nil method:RKRequestMethodPOST];
[self.objectManager addRequestDescriptor:requestDescriptor];
NSDictionary *data = [business toDictionary];
[self sendRequest:@"api/Business/Create" Method:@"POST" Data:data withCallback:^(BOOL success, NSDictionary response, NSError error) {
callback(success, response, error);
}];
KLInterestID.h
@interface KLInterestID : NSObject
@property (nonatomic) NSNumber *InterestID;
@end
请让我知道我做错了什么。我不熟悉relationshipMappingFromKeyPath
和attributeMappingFromKeyPath:nil
函数。
我不确定如何发送int
数组。
感谢