0

我将对象休息为:

@interface VFEQuestionnaireRest : NSObject
    @property(copy ,nonatomic) NSNumber *iid;
    @property(copy, nonatomic)NSString *namePoll;
    @property(copy, nonatomic)NSSet *questions;
@end

并将JSON作为:

    {"questionnaire":[
      {"id":4,"namePoll":"questionario4","questions":              
         {"id":13,"idQuestionnaire":4,"nameQuestion":"costo?",
            "questionType":{"id":2,"nameType":"WHOLE"}}}]}

值“iid”始终为“0”,namePoll 具有正确的值。如何将 int 值从 JSON 映射到NSNumberobjC?

-

RKObjectMapping *questionnaireMapping = [RKObjectMapping mappingForClass:[VFEQuestionnaireRest class]];
    [questionnaireMapping addAttributeMappingsFromDictionary:
     @{@"iid":@"id",
    @"namePoll":@"namePoll"
     }];
[questionnaireMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"questions" toKeyPath:@"questions"  withMapping:questionMapping]];
4

1 回答 1

1

我相信您的映射不正确。它应该是源 -> 目标,而不是相反:

RKObjectMapping *questionnaireMapping = [RKObjectMapping mappingForClass:[VFEQuestionnaireRest class]];
[questionnaireMapping addAttributeMappingsFromDictionary:
   @{ @"id":@"iid",
   @"namePoll":@"namePoll" }];

Restkit 自动执行 int -> NSNumber 转换。

于 2013-08-22T14:10:07.287 回答