我是 RestKit 和 Objective C 的新手。我正在尝试使用 RestKit 从 Web 服务中检索数据。我已经完成了映射,但有些我得到的错误是它找不到响应的匹配项。我使用没有 KVC 的映射,因为 JSON 格式没有密钥。
这是映射实现
+(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."}