0
这是API我的回应:的iOS RestKit - 测绘成果,只有一个属性
{"is_favorited":1}
我想RestKit映射,但我不能让它工作。这我在AppDelegate.m:
RKObjectMapping *isFavoriteMapping = [RKObjectMapping mappingForClass:[IsFavorite class]];
[isFavoriteMapping addAttributeMappingsFromDictionary:@{
@"is_favorited" : @"Is_favorited",
}];
RKResponseDescriptor *isFavoriteResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:isFavoriteMapping
method:RKRequestMethodAny
pathPattern:@"/api/isPointFavorited/:sid"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptor:isFavoriteResponseDescriptor];
路径是好的。我有地址令牌。我打电话通过:
RKObjectManager *manager = [RKObjectManager sharedManager];
[manager getObjectsAtPath: [NSString stringWithFormat:@"/api/isPointFavorited/%@", sid]
parameters:@{
@"pid":[NSString stringWithFormat:@"%@", actualPlace.Id]
}
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
...
}
failure:^(RKObjectRequestOperation *operation, NSError *error)
{
...
}];
我在应用程序和sid(登录令牌)中多次使用RestKit。所以地址或方法调用没有问题。问题必须在绘图中,但我不知道如何去做。我试图将keyPath从零修改为@“is_favorited”,但它没有帮助。
我Is_favorite.h:
@interface IsFavorite : NSObject
@property(nonatomic) NSNumber *Is_favorited;
@end
RestKit错误:
Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0x1849cbc0 {DetailedErrors=(
), NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: events, results
The representation inputted to the mapper was found to contain nested object representations at the following key paths: is_favorited
This likely indicates that you have misconfigured the key paths for your mappings., NSLocalizedDescription=No mappable object representations were found at the key paths searched., keyPath=null}
编辑 - 改变的AppDelegate,但仍无法正常工作:
RKObjectMapping *isFavoriteMapping = [RKObjectMapping mappingForClass:[IsFavorite class]];
[isFavoriteMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"Is_favorited"]];
RKResponseDescriptor *isFavoriteResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:isFavoriteMapping
method:RKRequestMethodAny
pathPattern:@"/api/isPointFavorited/:sid"
keyPath:@"is_favorited"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptor:isFavoriteResponseDescriptor];
仍然不能正常工作:/ –
那JSON显示了整个JSON吗?错误消息引用'events,results' ... – Wain
是的,那个引用是我的AppDelegate中的其他映射和响应描述符(这些从我设置keyPath的映射和响应描述符中是很少的)。 –