我一直在尝试从 JSON 响应和我在控制台输出中看到的所有内容中映射以下对象,没有任何原因导致映射不成功 - 如果有人可以检查并查看,我将不胜感激:
@interface RKElectionsModel : NSObject
@property (nonatomic, assign) bool isActive;
@property (nonatomic, strong) NSNumber *electionID;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *summary;
@property (nonatomic, strong) NSNumber *availableSeats;
@property (nonatomic, strong) NSNumber *candidatesCount;
@property (nonatomic, strong) NSNumber *withdrawnCount;
@property (nonatomic, strong) NSSet *candidates;
@end
/**
* Election Detail Mapping: Getting all election details, we have some extra information from
* the API call
*
*/
RKObjectMapping *electionDetailsMapping = [RKObjectMapping mappingForClass:[RKElectionsModel class]];
// Map JSON -> entities
[electionDetailsMapping addAttributeMappingsFromDictionary:@{
@"id": @"electionID",
@"title": @"title",
@"summary": @"summary",
@"active": @"isActive",
@"availableSeats": @"availableSeats",
@"candidatesCount": @"candidatesCount",
@"withdrawnCount": @"withdrawnCount"
}];
// Register our mappings with the provider
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:electionDetailsMapping pathPattern:@"/api/elections/:electionID/all" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
pastebin 上的控制台输出以及您可以在此处访问的任何 JSON 响应示例
感谢任何帮助,刘易斯