好的,所以我几乎回顾了这个网站上的其他每一个问题都无济于事。
这是我从REST服务返回的JSON:
{
"errors" : {};
"result" : {
"messagebody" : "Hello!";
"timestamp" : "2014-08-21T04:12:28.4689099+00:00";
};
"success" : {};
}
我试图通过RestKit v0.20.3拉出结果对象
这是我的代码块,它被配置/执行:
- (void) configureRestKit
{
NSURL *cminstance = [NSURL URLWithString:@"http://<domain>"];
AFHTTPClient *cmclient = [[AFHTTPClient alloc] initWithBaseURL:cminstance];
RKObjectManager *objmgr = [[RKObjectManager alloc] initWithHTTPClient:cmclient];
RKObjectMapping *messageMap = [RKObjectMapping mappingForClass:[Message class]];
[messageMap addAttributeMappingsFromDictionary:@{ @"messagebody" : @"messagebody", @"timestamp": @"timestamp"}];
messageMap.forceCollectionMapping = YES;
RKResponseDescriptor *descriptor =
[RKResponseDescriptor
responseDescriptorWithMapping:messageMap
method:RKRequestMethodGET
pathPattern:@"/v1/app/e51cb2dd24af47a49232b942210e758d/text?f=test"
keyPath:@"result"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objmgr addResponseDescriptor:descriptor];
}
- (IBAction)helloButtonClicked:(id)sender {
[[RKObjectManager sharedManager].HTTPClient setDefaultHeader:@"X-App-ApiKey" value:@"2c130c75dc9f4c2c8ef7c8753e8b7c56"];
NSLog(@"ResponseDescriptors %@", [[RKObjectManager sharedManager] responseDescriptors]);
[[RKObjectManager sharedManager] getObjectsAtPath:@"/v1/app/e51cb2dd24af47a49232b942210e758d/text?f=test" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
_Response.text = [mappingResult.dictionary objectForKey:@"messagebody"];
} failure:^(RKObjectRequestOperation *operation, NSError *error)
{
_Response.text = @"Something went wrong.";
}];
}
以下是跟踪错误:
2014-08-21 00:12:30.653 The-App [13924:3707] E restkit.network:RKObjectRequestOperation.m:208 GET'http:/// v1 / app / e51cb2dd24af47a49232b942210e758d / text?f = test' (200 OK / 0个对象)[request = 2.7297s mapping = 0.0000s total = 2.7365s]: error = Error Domain = org.restkit.RestKit.ErrorDomain Code = 1001“没有响应描述符与加载的响应匹配。” UserInfo = 0xb164380 {NSErrorFailingURLStringKey = http:/// v1 / app / e51cb2dd24af47a49232b942210e758d / text?f = test,NSLocalizedFailureReason =从网址加载200响应'http:/// v1 / app / e51cb2dd24af47a49232b942210e758d / text?f = test ',它无法匹配所有(0)响应描述符:,NSLocalizedDescription =没有响应描述符匹配加载的响应。,keyPath = null,NSErrorFailingURLKey = http:/// v1 / app / e51cb2dd24af47a49232b942210e758d / text?f = test,NSUnderlyingError = 0xb1641c0“在搜索的关键路径中找不到可映射的对象表示。”} response.body = { “成功”:{}, “错误”:{}, “结果”:{ “消息体”: “你好!”, “时间戳”:“2014-08-21T04:12:28.4689099 + 00: 00" }}
这里有关于如何进行故障排除的任何想法?我一直在敲打这个问题几个小时,谷歌并不是我的朋友。
编辑:响应描述符
2014-08-22 10:41:21.580 Apprenda-CloudMine-App[10987:60b] ResponseDescriptors (
"<RKResponseDescriptor: 0x17826c180 method=(GET) pathPattern=/v1/app/e51cb2dd24af47a49232b942210e758d/text?f=test keyPath=result statusCodes=200-299 : <RKObjectMapping:0x17826bfc0 objectClass=Message propertyMappings=(\n \"<RKAttributeMapping: 0x1780499f0 timestamp => timestamp>\",\n \"<RKAttributeMapping: 0x17804cf30 messagebody => messagebody>\"\n)>>"
)
谢谢! -Chris
答案 0 :(得分:5)
该错误表示您的请求与您的响应描述符之间的路径不匹配。它很微妙,错误消息中的(0) response descriptors
也向我表明该路径没有响应描述符。有关RestKit路径不匹配的错误消息的详细信息,请参阅this GitHub问题。
为什么你的路径不匹配?毕竟,您的请求中的路径与您的响应描述符中的路径完全相同。您的问题似乎可能是响应描述符路径中指定的GET参数。您需要从响应描述符路径中删除get参数,因为它在技术上不是路径的一部分。
应该是以下内容。
[RKResponseDescriptor
responseDescriptorWithMapping:messageMap
method:RKRequestMethodGET
pathPattern:@"/v1/app/e51cb2dd24af47a49232b942210e758d/text"
keyPath:@"result"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
感谢Flaviu Simihaian实现此目标。