全部 ...
我整个周末都在这个问题上,问题仍然存在。我不知道还能做什么,任何帮助将不胜感激。我正在尝试像这样发送 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 只需要一个对象来发布。
...这是我尝试这样做的代码:
@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;
}