Restkit返回具有0个键值对的对象数组

时间:2016-01-15 19:46:10

标签: objective-c restkit

我不确定我在这里缺少什么。对于此请求,我获得了一个JSON响应,其关键路径为“data.file”。响应描述符因此设置:

[fileMapping addAttributeMappingsFromDictionary:@{@"parentPath" : @"parentPath"}];

RKResponseDescriptor *fileResponseDescriptorFile =
    [RKResponseDescriptor responseDescriptorWithMapping:fileMapping
                    method:RKRequestMethodAny
               pathPattern:nil
                   keyPath:@"data.file"
               statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 

getObjectsAtPath调用的成功块被触发,从那里映射results.array显示一个对象数组,但没有键值对。

an array of objects but with no key value pairs

如果我手动反序列化JSON,我会正确填充键值对。

NSDictionary* json = [NSJSONSerialization JSONObjectWithData:operation.HTTPRequestOperation.responseData options:NSJSONReadingMutableContainers error:nil];
        NSDictionary *data=[json objectForKey:@"data"];
        NSArray *files = [data objectForKey:@"file"];
        NSLog(@"files: %@", files);

以下是JSON的片段:

{
"data": {
    "folder": [
        {
            "parentPath": "xxx",
            "name": "xxx",
            "versionCreated": "2015-12-11T19:26:19.782Z"
        }
    ],
    "file": [
        {
            "parentPath": "xxx",
            "name": "2015-09-18 104310-4377094.JPG",
            "size": 4377094,
            "checksum": "5988e769689095c6512a3b5382e92677e0aa495b8a2d71506d3ca24b561f2dff",
            "contentToken": "xxx",
            "versionCreated": "2015-09-18T14:53:36.525Z",
            "version": 1,
            "systemAttributes": {
                "Capture-Date": "2015-09-18T14:43:10.000Z",
                "Geo-Latitude": 40.00000,
                "Geo-Longitude": -74.00000,
                "Height": 3024,
                "Mime-Type": "image/jpeg",
                "Orientation": 6,
                "Timeline-Date": "2015-09-18T14:43:10.000Z",
                "Width": 4032
            }
        }...

Restkit日志记录:

CloudAPIRestKit[86320:8464807] D restkit.object_mapping:RKMapperOperation.m:414 Executing mapping operation for representation: {
    data =     {
        file =         (
                        {
                checksum = xxx;
                contentToken = "xxx-gmkQ4oOO1c~";
                name = "2015-09-18 104310-4377094.JPG";
                parentPath = "/xxx";
                size = 4377094;
                systemAttributes =                 {
                    "Capture-Date" = "2015-09-18T14:43:10.000Z";
                    "Geo-Latitude" = "40.00000";
                    "Geo-Longitude" = "-74.00000";
                    Height = 3024;
                    "Mime-Type" = "image/jpeg";
                    Orientation = 6;
                    "Timeline-Date" = "2015-09-18T14:43:10.000Z";
                    Width = 4032;
                };
                version = 1;
                versionCreated = "2015-09-18T14:53:36.525Z";
            },...

} with mapping <RKObjectMapping:0x7fa958654190 objectClass=CloudFileModel propertyMappings=(
    "<RKAttributeMapping: 0x7fa958729b60 parentPath => parentPath>",
    "<RKAttributeMapping: 0x7fa958654500 name => name>"
)>
2016-01-18 09:50:31.262 CloudAPIRestKit[86320:8464807] D restkit.object_mapping:RKMappingOperation.m:1172 Starting mapping operation...
2016-01-18 09:50:31.263 CloudAPIRestKit[86320:8464807] T restkit.object_mapping:RKMappingOperation.m:1173 Performing mapping operation: <RKMappingOperation 0x7fa958696100> for 'CloudFileModel' object. Mapping values from object {
    checksum = xxx;
    contentToken = "xxx-xxx~";
    name = "2015-09-18 104310-4377094.JPG";
    parentPath = "/xxx";
    size = 4377094;
    systemAttributes =     {
        "Capture-Date" = "2015-09-18T14:43:10.000Z";
        "Geo-Latitude" = "40.00000";
        "Geo-Longitude" = "-74.00000";
        Height = 3024;
        "Mime-Type" = "image/jpeg";
        Orientation = 6;
        "Timeline-Date" = "2015-09-18T14:43:10.000Z";
        Width = 4032;
    };
    version = 1;
    versionCreated = "2015-09-18T14:53:36.525Z";
} to object <CloudFileModel: 0x7fa95a822d70> with object mapping (null)
2016-01-18 09:50:31.264 CloudAPIRestKit[86320:8464807] T restkit.object_mapping:RKMappingOperation.m:693 Found transformable value at keyPath 'parentPath'. Transforming from class '__NSCFString' to 'NSString'
2016-01-18 09:50:31.265 CloudAPIRestKit[86320:8464807] T restkit.object_mapping:RKMappingOperation.m:712 Mapping attribute value keyPath 'parentPath' to 'parentPath'
2016-01-18 09:50:31.265 CloudAPIRestKit[86320:8464807] T restkit.object_mapping:RKMappingOperation.m:728 Mapped attribute value from keyPath 'parentPath' to 'parentPath'. Value: /VZMOBILE/Cellco Test’s iPhone
2016-01-18 09:50:31.266 CloudAPIRestKit[86320:8464807] T restkit.object_mapping:RKMappingOperation.m:693 Found transformable value at keyPath 'name'. Transforming from class '__NSCFString' to 'NSString'
2016-01-18 09:50:31.266 CloudAPIRestKit[86320:8464807] T restkit.object_mapping:RKMappingOperation.m:712 Mapping attribute value keyPath 'name' to 'name'
2016-01-18 09:50:31.267 CloudAPIRestKit[86320:8464807] T restkit.object_mapping:RKMappingOperation.m:728 Mapped attribute value from keyPath 'name' to 'name'. Value: 2015-09-18 104310-4377094.JPG
2016-01-18 09:50:31.267 CloudAPIRestKit[86320:8464807] D restkit.object_mapping:RKMappingOperation.m:1273 Finished mapping operation successfully...
2016-01-18 09:50:31.268 CloudAPIRestKit[86320:8464807] D restkit.object_mapping:RKMapperOperation.m:258 Asked to map source object {
    checksum = xxx;
    contentToken = "xxx-duHZ0DyOA-g~";
    name = "2015-09-18 104307-3859795.JPG";
    parentPath = "/xxx";
    size = 3859795;
    systemAttributes =     {
        "Capture-Date" = "2015-09-18T14:43:07.000Z";
        "Geo-Latitude" = "40.00000";
        "Geo-Longitude" = "-74.00000";
        Height = 3024;
        "Mime-Type" = "image/jpeg";
        Orientation = 6;
        "Timeline-Date" = "2015-09-18T14:43:07.000Z";
        Width = 4032;
    };
    version = 1;
    versionCreated = "2015-09-18T14:53:19.610Z";
} with mapping <RKObjectMapping:0x7fa958654190 objectClass=CloudFileModel propertyMappings=(
    "<RKAttributeMapping: 0x7fa958729b60 parentPath => parentPath>",
    "<RKAttributeMapping: 0x7fa958654500 name => name>"
)>...
2016-01-18 09:50:33.803 CloudAPIRestKit[86320:8464807] D restkit.object_mapping:RKMappingOperation.m:1172 Starting mapping operation...

2016-01-18 09:50:33.901 CloudAPIRestKit[86320:8464807] D restkit.object_mapping:RKMappingOperation.m:1172 Starting mapping operation...
2016-01-18 09:50:33.902 CloudAPIRestKit[86320:8464807] T restkit.object_mapping:RKMappingOperation.m:1173 Performing mapping operation: <RKMappingOperation 0x7fa95ab51040> for 'CloudFileModel' object. Mapping values from object {
    checksum = xxx;
    contentToken = "xxx~";
    name = "2015-06-26 133729-1708809.JPG";
    parentPath = "/xxx";
    size = 1708809;
    systemAttributes =     {
        "Capture-Date" = "2015-06-26T17:37:29.000Z";
        "Geo-Latitude" = "40.00000";
        "Geo-Longitude" = "-74.00000";
        Height = 2448;
        "Mime-Type" = "image/jpeg";
        Orientation = 6;
        "Timeline-Date" = "2015-06-26T17:37:29.000Z";
        Width = 3264;
    };
    version = 4;
    versionCreated = "2015-09-16T19:51:37.749Z";
} to object <CloudFileModel: 0x7fa95aa212b0> with object mapping (null)

这是调试器在[[RKObjectRequestOperation responseMappingQueue] addOperation:self.responseMapperOperation];

之前显示的内容

restkit glimpse

1 个答案:

答案 0 :(得分:0)

也许,您还没有将描述符添加到对象管理器中:

[objectManager addResponseDescriptor:responseDescriptor];