2013-02-17 16 views
5

Ich arbeite an Objective C Projekt, das RestKit Framework für die Analyse von JSON-Antworten verwendet. Jetzt brauche ich etwas Hilfe mit Objekt-Mapping-Einstellungen für folgenden Fall: JSON Antwort:RestKit 0,20 - Dynamisches verschachteltes Objekt-Mapping

{ 
    "data": { 
     "SOME.API.Auth": { 
      "maxVersion": 2, 
      "minVersion": 1, 
      "path": "auth.cgi" 
     }, 
     "SOME.Station": { 
      "maxVersion": 1, 
      "minVersion": 1, 
      "path": "Station/task.cgi" 
     } 
    }, 
    "success": true 
} 

und folgende Objekte:

@interface Response : NSObject 
@property (strong, nonatomic) NSArray *data; 
@property (assign, nonatomic) BOOL success; 
@end 


@interface SomeAPIInfo : NSObject 
@property (strong, nonatomic) NSString *name; 
@property (strong, nonatomic) NSString *path; 
@property (strong, nonatomic) NSString *minVersion; 
@property (strong, nonatomic) NSString *maxVersion; 
@end 

Und hier ist meine Mapping-Einstellungen:

RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[Response class]]; 
[responseMapping addAttributeMappingsFromDictionary:@{@"success": @"success"}]; 

RKObjectMapping *dataObjectMapping = [RKObjectMapping mappingForClass:[SomeAPIInfo class]]; 
dataObjectMapping.forceCollectionMapping = YES; 
[dataObjectMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"name"]; 
[dataObjectMapping addAttributeMappingsFromDictionary:@{ 
@"(name).path": @"path", 
@"(name).minVersion": @"minVersion", 
@"(name).maxVersion": @"maxVersion"}]; 


[responseMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"data" 
                       toKeyPath:@"data" 
                      withMapping:dataObjectMapping]]; 

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping 
                        pathPattern:nil 
                         keyPath:nil 
                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 


[_objectManager addResponseDescriptor:responseDescriptor]; 

Problem ist, dass das Objekt "data" nicht korrekt zugeordnet ist: NSArray * data; ist mit 2 "SomeAPIInfo" -Objekten gefüllt. Der Name ist korrekt ausgefüllt, aber andere Werte (Pfad, maxVersion, minVersion) sind leer.

Was mache ich falsch? Gibt es eine andere Möglichkeit, ein "Daten" -Objekt zuzuordnen? Vielleicht direkt in NSDictionary, also wäre "Some.API.Auth" ein Schlüssel und "SomeAPIInfo" wäre ein Objekt (ohne "name" -Eigenschaft).

Vielen Dank für Ihre Hilfe!

Edit:. Ich denke, dass die Zuordnung nicht, weil die Punkte in Schlüssel funktioniert ("SOME.API.Auth)

RKMappingOperation.m: 
- (NSArray *)simpleAttributeMappings 
{ 
    NSMutableArray *mappings = [NSMutableArray array]; 
    for (RKAttributeMapping *mapping in self.nestedAttributeMappings) { 
     if ([mapping.sourceKeyPath rangeOfString:@"."].location == NSNotFound) { 
      [mappings addObject:mapping]; 
     } 
    } 

Antwort

0

Ich lief in ähnliche Probleme, die durch einen Fehler verursacht wurden in RestKit https://github.com/RestKit/RestKit/issues/1532. Ich würde versuchen, das mögliche Punktproblem zu beseitigen, indem ich eine gefälschte JSON Antwort mit der gleichen Struktur aber ohne die Punkte verursache und sehe, ob das Problem dort noch vorhanden ist.