gpt4 book ai didi

ios - RestKit - 错误域代码 1001

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:27:47 25 4
gpt4 key购买 nike

好吧,我已经复习了该站点上几乎所有其他问题,但无济于事。

这是我从 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 objects) [request=2.7297s mapping=0.0000s total=2.7365s]: error=Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0xb164380 {NSErrorFailingURLStringKey=http:///v1/app/e51cb2dd24af47a49232b942210e758d/text?f=test, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http:///v1/app/e51cb2dd24af47a49232b942210e758d/text?f=test', which failed to match all (0) response descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http:///v1/app/e51cb2dd24af47a49232b942210e758d/text?f=test, NSUnderlyingError=0xb1641c0 "No mappable object representations were found at the key paths searched."} response.body={"success":{},"errors":{},"result":{"messagebody":"Hello!","timestamp":"2014-08-21T04:12:28.4689099+00:00"}}

这里有关于如何排除故障的任何想法吗?几个小时以来,我一直在努力解决这个问题,而谷歌并不是我的 friend 。

编辑响应描述符

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)>>"

)

谢谢!-克里斯

最佳答案

该错误表明您的请求和响应描述符之间的路径不匹配。这很微妙,错误消息中的 (0) 响应描述符 还向我表明该路径没有响应描述符。有关 RestKit 路径不匹配的错误消息的更多信息,请参阅 this GitHub 问题。

那你为什么会遇到路径不匹配?毕竟,请求中的路径与响应描述符中的路径完全相同。看起来您的问题很可能是响应描述符路径中指定的 GET 参数。您需要从响应描述符路径中删除 get 参数,因为它在技术上不是路径的一部分。

应该是下面的内容。

[RKResponseDescriptor
responseDescriptorWithMapping:messageMap
method:RKRequestMethodGET
pathPattern:@"/v1/app/e51cb2dd24af47a49232b942210e758d/text"
keyPath:@"result"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

感谢Flaviu Simihaian为了实现这一点。

关于ios - RestKit - 错误域代码 1001,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25418264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com