我是RestKit和Objective C的新手。我试图从带有RestKit的Web服务中检索数据。我已经完成了映射,但一些我得到的错误,它无法找到匹配的响应。由于JSON格式没有密钥,因此我使用的是没有KVC的映射。Restkit映射 - 没有响应描述符匹配加载的响应
这里是映射实现
+(RKObjectMapping *)venueMapping {
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[venue class]];
NSDictionary *mappingDictionary = @{@"name":@"name"};
[mapping addAttributeMappingsFromDictionary:mappingDictionary];
return mapping;
}
我只有一个值,想看看是否有任何匹配。下面是回复描述符
-(void) loadVenue:(void (^)(venue *))success failure:(void (^)(RKObjectRequestOperation *, NSError *))failure{
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
[self getObjectsAtPath:@"venue" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
if(success){
venue *venues = (venue *)[mappingResult.array firstObject];
success(venues);
}
}failure:^(RKObjectRequestOperation *operation, NSError *error){
if(failure){
failure(operation,error);
}
}];
}
- (void) setupResponseDescriptors {
[super setupResponseDescriptiors];
RKResponseDescriptor *authenticatedUserResponseDescriptors = [RKResponseDescriptor responseDescriptorWithMapping:[MappingProvider venueMapping] method:RKRequestMethodGET pathPattern:@"venue" keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self addResponseDescriptor:authenticatedUserResponseDescriptors];
}
我一直在阅读文档并尝试各种方法,但我仍然没有解决这个问题。任何人有任何想法?
附加是一个示例JSON返回。
(
{
coverType = "<null>";
description = "";
name = "McDonald";
priv = 1;
rates =();
},
{
coverType = "<null>";
description = "";
name = "My House";
priv = 1;
rates =();
},
)
新增追踪日志
2014-04-22 21:45:55.636 App_Test[420:60b] I restkit:RKLog.m:34 RestKit logging initialized...
2014-04-22 21:45:56.064 App_Test[420:60b] I restkit.network:RKObjectRequestOperation.m:180 GET 'http://api.kontakt.io/venue'
2014-04-22 21:46:46.327 App_Test[420:f03] D restkit.object_mapping:RKMapperOperation.m:377 Executing mapping operation for representation: (
{
beacons = (
);
beaconsCount = 0;
coverType = "<null>";
description = "";
id = "212321";
lat = "<null>";
lng = "<null>";
managers = (
);
name = McDonald;
priv = 1;
rates = (
);
users = (
);
}
)
and targetObject: (null)
2014-04-22 21:46:46.328 App_Test[420:f03] D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: (null)
2014-04-22 21:46:46.328 App_Test[420:570b] E restkit.network:RKObjectRequestOperation.m:243 GET 'http://api.kontakt.io/venue' (200 OK/0 objects) [request=0.9645s mapping=0.0000s total=50.3422s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x9556ab0 {NSErrorFailingURLStringKey=http://api.kontakt.io/venue, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://api.kontakt.io/venue', which failed to match all (0) response descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://api.kontakt.io/venue, NSUnderlyingError=0x9557c30 "No mappable object representations were found at the key paths searched."}
我试图把整个映射在代码中,这不是正确映射情况。但似乎它仍然无法正常工作。不过,我在调试期间发现了这个错误,** NSUnderlyingError:摘要字符串解析错误**。这是否意味着我的映射声明有一些问题? – greenhatman
进一步调试后,似乎baseURL不匹配。不太确定发生了什么事。将尝试进一步调试 – greenhatman
您能否为响应添加跟踪日志输出?并将响应描述符键路径更改为'nil'。 – Wain