RestKit: mapping JSON array of strings

后端 未结 3 1451
甜味超标
甜味超标 2020-12-30 18:14

Given the following JSON:

{
   \"someKey\":\"someValue\",
   \"otherKey\":\"otherValue\",
   \"features\":[
      \"feature1\",
      \"feature2\",
      \"f         


        
3条回答
  •  無奈伤痛
    2020-12-30 18:18

    You need to use a nil key path:

    RKEntityMapping *featureMapping = [RKEntityMapping mappingForEntityForName:...];
    [featureMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"name"]];
    featureMapping.identificationAttributes = @[ @"name" ];
    

    Then, on your top level object mapping, define the relationship:

    [topMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"features" toKeyPath:@"features" withMapping:featureMapping]];
    

    In your feature (in the model), myTopLevelObject should be defined as a bi-directional relationship to the top level object.

提交回复
热议问题