Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Restkit中映射单个JSON对象时出错_Ios_Objective C_Json_Restkit - Fatal编程技术网

Ios 在Restkit中映射单个JSON对象时出错

Ios 在Restkit中映射单个JSON对象时出错,ios,objective-c,json,restkit,Ios,Objective C,Json,Restkit,我无法将JSON响应映射到Objective-C对象 以下是答复的内容: { "pin": { "title": "Donkey Kong Tower", "description": "This is an article with #suchhashtag because it's awesome!", "_id": "538054c107bf5b0b00795b82", "user": "5380cc64db86cc0b002cdc63", "updatedAt": "2014-06-15

我无法将JSON响应映射到Objective-C对象

以下是答复的内容:

{
"pin": {
"title": "Donkey Kong Tower",
"description": "This is an article with #suchhashtag because it's awesome!",
"_id": "538054c107bf5b0b00795b82",
"user": "5380cc64db86cc0b002cdc63",
"updatedAt": "2014-06-15T21:34:41.891Z",
"createdAt": "2014-06-15T21:34:41.891Z",
"coordinates": {
  "latitude": 48.1678645,
  "longitude": 11.5861475
},
"id": "538054c107bf5b0b00795b82"
}
}
相应的对象标头如下所示:

@interface Pin : NSObject

@property (strong, nonatomic) NSString *identifier;
@property (strong, nonatomic) NSString *description;
@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *latitude;
@property (strong, nonatomic) NSString *longitude;
@property (strong, nonatomic) NSString *userId;
@property (strong, nonatomic) NSString *pictureId;
@property (strong, nonatomic) NSString *recordingId;

@end
最后是映射设置:

RKObjectMapping* pinMapping = [RKObjectMapping mappingForClass:[Pin class]];

[pinMapping addAttributeMappingsFromDictionary:@{@"coordinates.latitude": @"latitude",
                                            @"coordinates.longitude": @"longitude", 
                                            @"id": @"identifier", 
                                            @"user" : @"userId", 
                                            @"title" : @"title",
                                            @"pictureId": @"pictureId", 
                                            @"recordingId": @"recordingId", 
                                            @"description" : @"description"}];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://server.herokuapp.com/pins/%@?access_token=%@", identifier, accessToken]]];

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor     
                                        responseDescriptorWithMapping:pinMapping 
                                        method:RKRequestMethodAny 
                                        pathPattern:nil 
                                        keyPath:@"pin" 
                                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request 
                                        responseDescriptors:@[responseDescriptor]];

[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

} failure:^(RKObjectRequestOperation *operation, NSError *error) {
  RKLogError(@"Operation failed with error: %@", error);
}];
[objectRequestOperation start];
日志文件表明映射确实有效,但结果对象仅包含描述字段的内容

restkit.object_mapping:RKMapperOperation.m:229 Asked to map source object {
    "_id" = 538054c107bf5b0b00795b82;
    coordinates =     {
        latitude = "48.1678645";
        longitude = "11.5861475";
    };
    createdAt = "2014-06-15T21:36:08.412Z";
    description = "This is an article with #suchhashtag because it's awesome!";
    id = 538054c107bf5b0b00795b82;
    title = "Donkey Kong Tower";
    updatedAt = "2014-06-15T21:36:08.412Z";
    user = 5380cc64db86cc0b002cdc63;
} with mapping <RKObjectMapping:0x10b351d60 objectClass=Pin propertyMappings=(
    "<RKAttributeMapping: 0x10b35b170 _id => identifier>",
    "<RKAttributeMapping: 0x10b3555d0 coordinates.latitude => latitude>",
    "<RKAttributeMapping: 0x10b355020 pictureId => pictureId>",
    "<RKAttributeMapping: 0x10b355370 recordingId => recordingId>",
    "<RKAttributeMapping: 0x10b330cd0 title => title>",
    "<RKAttributeMapping: 0x10b356ee0 coordinates.longitude => longitude>",
    "<RKAttributeMapping: 0x10b357400 description => description>",
    "<RKAttributeMapping: 0x10b356d10 user => userId>"
)>
2014-06-15 23:36:08.454 Remarkable[7523:f03] D restkit.object_mapping:RKMappingOperation.m:859 Starting mapping operation...
2014-06-15 23:36:08.454 Remarkable[7523:f03] T restkit.object_mapping:RKMappingOperation.m:860 Performing mapping operation: <RKMappingOperation 0x10b3646f0> for 'Pin' object. Mapping values from object {
    "_id" = 538054c107bf5b0b00795b82;
    coordinates =     {
        latitude = "48.1678645";
        longitude = "11.5861475";
    };
    createdAt = "2014-06-15T21:36:08.412Z";
    description = "This is an article with #suchhashtag because it's awesome!";
    id = 538054c107bf5b0b00795b82;
    title = "Donkey Kong Tower";
    updatedAt = "2014-06-15T21:36:08.412Z";
    user = 5380cc64db86cc0b002cdc63;
} to object *nil description* with object mapping (null)
restkit.object_mapping:RKMappingOperation.m:438 Found transformable value at keyPath '_id'. Transforming from class '__NSCFString' to 'NSString'
restkit.object_mapping:RKMappingOperation.m:453 Mapping attribute value keyPath '_id' to 'identifier'
restkit.object_mapping:RKMappingOperation.m:469 Mapped attribute value from keyPath '_id' to 'identifier'. Value: 538054c107bf5b0b00795b82
restkit.object_mapping:RKMappingOperation.m:518 Did not find mappable attribute value keyPath 'pictureId'
restkit.object_mapping:RKMappingOperation.m:518 Did not find mappable attribute value keyPath 'recordingId'
restkit.object_mapping:RKMappingOperation.m:438 Found transformable value at keyPath 'title'. Transforming from class '__NSCFString' to 'NSString'
restkit.object_mapping:RKMappingOperation.m:453 Mapping attribute value keyPath 'title' to 'title'
restkit.object_mapping:RKMappingOperation.m:469 Mapped attribute value from keyPath 'title' to 'title'. Value: Donkey Kong Tower
restkit.object_mapping:RKMappingOperation.m:438 Found transformable value at keyPath 'description'. Transforming from class '__NSCFString' to 'NSString'
restkit.object_mapping:RKMappingOperation.m:453 Mapping attribute value keyPath 'description' to 'description'
restkit.object_mapping:RKMappingOperation.m:469 Mapped attribute value from keyPath 'description' to 'description'. Value: This is an article with #suchhashtag because it's awesome!
restkit.object_mapping:RKMappingOperation.m:438 Found transformable value at keyPath 'user'. Transforming from class '__NSCFString' to 'NSString'
restkit.object_mapping:RKMappingOperation.m:453 Mapping attribute value keyPath 'user' to 'userId'
restkit.object_mapping:RKMappingOperation.m:469 Mapped attribute value from keyPath 'user' to 'userId'. Value: 5380cc64db86cc0b002cdc63
restkit.object_mapping:RKMappingOperation.m:438 Found transformable value at keyPath 'coordinates.latitude'. Transforming from class '__NSCFNumber' to 'NSString'
restkit.object_mapping:RKMappingOperation.m:453 Mapping attribute value keyPath 'coordinates.latitude' to 'latitude'
restkit.object_mapping:RKMappingOperation.m:469 Mapped attribute value from keyPath 'coordinates.latitude' to 'latitude'. Value: 48.1678645
restkit.object_mapping:RKMappingOperation.m:438 Found transformable value at keyPath 'coordinates.longitude'. Transforming from class '__NSCFNumber' to 'NSString'
restkit.object_mapping:RKMappingOperation.m:453 Mapping attribute value keyPath 'coordinates.longitude' to 'longitude'
restkit.object_mapping:RKMappingOperation.m:469 Mapped attribute value from keyPath 'coordinates.longitude' to 'longitude'. Value: 11.5861475
restkit.object_mapping:RKMappingOperation.m:928 Finished mapping operation successfully...
restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: {
    pin = "This is an article with #suchhashtag because it's awesome!";
    }
部分。
另一个StackOverflow问题也有类似的问题:,但没有明确的解决方案。

因为是用于返回实例描述的预定义方法-不要通过添加自己的同名属性来覆盖它

将属性的名称更改为“overview”或类似的名称,并更新映射目标键

to object *nil description* with object mapping (null)