这应该是一个非常简单的,但遗憾的是我没有找到任何答案......
RestKit将我的对象映射到:
request.body={"user":{"pass":"1234","id":0,"login":"awesome_guy","tier":0}}
我真正想要的是什么:
{"pass":"1234","id":0,"login":"awesome_guy","tier":0}
没有对象名称“user”。
如果您已经处理过此问题,则需要5秒钟才能回答。如果你还没有使用过RestKit。你不知道答案。无论如何我附上了我的代码:
用户对象映射:
/* ===========================
* ====User Object Mapping====
* ==========================*/
RKEntityMapping* userObjectMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([User class]) inManagedObjectStore:objectManager.managedObjectStore];
NSDictionary *userObjectMappingDict = @{
@"id":@"id",
@"login":@"login",
@"firstName":@"firstName",
@"lastName":@"lastName",
@"phoneNumber":@"phoneNumber",
@"email":@"email",
@"tier":@"tier",
@"sessionId":@"sessionId",
@"pass":@"password"
};
userObjectMapping.identificationAttributes = @[@"id"];
[userObjectMapping addAttributeMappingsFromDictionary:userObjectMappingDict];
RKEntityMapping* userBusinessMapping = [RKEntityMapping mappingForEntityForName:@"Business" inManagedObjectStore:objectManager.managedObjectStore];
[userBusinessMapping addAttributeMappingsFromDictionary:@{@"business":@"id"}]; // Nil Key path
[userObjectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:nil toKeyPath:@"business" withMapping:userBusinessMapping]];
答案 0 :(得分:1)
您应该有一个未显示的RKRequestDescriptor
实例。它是使用requestDescriptorWithMapping:objectClass:rootKeyPath:
创建的。您将根密钥路径设置为@"user"
,并且应将其设置为nil。