我想在情节提要上显示我从服务器获得的响应主体,我正在做这样的连接。当我运行该应用程序时,我得到以下响应:
response.body={"id":2,"token":"xyzzyzzyx"}
2013-11-05 11:36:52.405 networkTest3[1327:70b] It Worked: (
"<LoginResponse: 0x8b508a0>"
)
我试图在 masterview 上显示来自 LoginResponse 的数据,遵循 CoffeeShop 示例,但由于 RestKit 版本(我现在使用的是最后一个版本,0.20),似乎很多事情都不同。我已经知道如何将类中的数据连接到接口上的 Outlets,但我无法找到如何从响应正文中获取数据。
我试图在类 LoginResponse 上使用此方法
- (void)loadToken{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[LoginResponse class]];
[mapping addAttributeMappingsFromDictionary:@{
@"id": @"status",
@"token": @"token",
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:nil keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
NSURL *URL = [NSURL URLWithString:@"http://myurl.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]];
[objectRequestOperation start];
}
我得到了这个:
2013-11-05 12:09:56.867 networkTest3[1585:3307] E restkit.network:RKObjectRequestOperation.m:576 Object request failed: Underlying HTTP request operation failed with error: (null)
我做错了什么,我的下一步是什么?
编辑:我试图在 LoginManager.m 上添加这个
[responseMapping addAttributeMappingsFromDictionary:@{@"id" : @"id", @"token" : @"token"}];
但我得到了
libc++abi.dylib: terminating with uncaught exception of type NSException
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to add mapping for keyPath token, one already exists...'