Restkit Mapping - 没有响应描述符与加载的响应匹配

时间:2014-04-20 11:49:58

标签: json ios7 restkit kvc

我是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 =();
    },
 )

添加了TraceLog

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."}

3 个答案:

答案 0 :(得分:4)

错误消息显示:

  

无法匹配所有(0)响应描述符

这表明(由于消息中的(0))未调用setupResponseDescriptors方法,因此没有响应描述符被添加到对象管理器。

答案 1 :(得分:0)

您正试图在路径“场地”处获取对象,但似乎没有任何迹象表明您的JSON中有“场地”对象。

答案 2 :(得分:0)

如果您不使用CoreData,请确保您的Podfile中定义了Restkit,如下所示

pod 'RestKit/Network', '~> 0.23' pod 'RestKit/ObjectMapping', '~> 0.23'