2017-01-22 2 views
0

Ich verwende JSONModel für die Arbeit mit einem JSON Api und jetzt bei der Analyse eines Dictionary of Dictionaries stecken geblieben.Parsen Sie ein Wörterbuch von Wörterbüchern mit JSONModel

{ 
    "locations": { 
    "one": { 
     "displayName": "Name One", 
     "description": "Description One" 
    }, 
    "two": { 
     "displayName": "Name Two", 
     "description": "Description Two" 
    } 
    } 
} 

In meinem Beispiel, ich brauche die Tasten „eins“ und „zwei“ und dessen Inhalt so dachte ich über so etwas wie diese

@protocol BaseDataModel; 

@interface BaseDataModel : JSONModel 

@property (nonatomic) NSDictionary<NSString *, LocationModel> *locations; 

@end 

Aber das wird nicht funktionieren, weil LocationModel nicht ist ein Ziel-C-Typ.

Antwort

1

Sie sollten nur die Klasse LocationModel erstellen:

@interface LocationModel : JSONModel 

@property (nonatomic) NSString * displayName; 
@property (nonatomic) NSString * description; 

@end 
0

Sie sind für Ihr LocationModel die @protocol Erklärung nur fehlt Ich denke

#import "JSONModel.h" 

@protocol LocationModel; 
@interface LocationModel : JSONModel 

@property (nonatomic, retain) NSString *displayName; 
@property (nonatomic, retain) NSString *description; 

@end 
Verwandte Themen