所有......
我整个周末都在这上面,问题仍然存在。我不知道还能做什么,非常感谢任何帮助。我正试图像这样发送JSON:
{
"proof":
{
"name":"fluff",
"media_type":"Photo",
"description":"This is a description"
},
"auth_token":"mphxNcEGJMJyU7iPmaLw"
}
我一直从RestKit获得以下异常:
2012-07-23 10:29:17.001 restkittest [8389:707] * 由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[valueForUndefinedKey:]:此类不是密钥符号编码兼容密钥auth_token。'
我怀疑是因为auth_token不是我传递的对象(证据)的一部分,但我不知道如何传递auth_token以及证明,因为postObject只需要一个对象发布。< / p>
...这是我尝试这样做的代码:
@implementation proof
@synthesize name;
@synthesize description;
@synthesize media_type;
@synthesize duration;
@synthesize frequency_id;
@end
@implementation auth_token
@synthesize auth_token;
@end
- (BOOL)createProof:(proof *)proof
{
BOOL ret = NO;
[self.objectManager postObject:proof usingBlock:^(RKObjectLoader *loader)
{
loader.delegate = self;
RKObjectMapping *proofMappingAccept = [RKObjectMapping mappingForClass:[proof class]];
[proofMappingAccept mapKeyPath:@"name" toAttribute:@"name"];
[proofMappingAccept mapKeyPath:@"description" toAttribute:@"description"];
[proofMappingAccept mapKeyPath:@"media_type" toAttribute:@"media_type"];
[proofMappingAccept mapKeyPath:@"duration" toAttribute:@"duration"];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[mapping mapKeyPath:@"auth_token" toAttribute:@"auth_token"];
[mapping mapKeyPath:@"proof" toRelationship:@"proof" withMapping:proofMappingAccept];
loader.serializationMapping = [mapping inverseMapping];
loader.objectMapping = mapping;
}];
return ret;
}
答案 0 :(得分:1)
使用您的校样对象创建一个NSDictionary作为密钥的值&#34;证明&#34;并将您的auth_token作为密钥的对象&#34; auth_token&#34;并将loader.sourceObject设置为此字典。