0

I'm using JSONModel for working with a JSON Api and now got stuck on parsing a Dictionary of Dictionaries.

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

In my example, I need the keys "one" and "two" and their content so I thought about something like this

@protocol BaseDataModel;

@interface BaseDataModel : JSONModel

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

@end

But this won't work because LocationModel isn't a Objective-C Type.

PascalTurbo
  • 2,189
  • 3
  • 24
  • 41

2 Answers2

1

You should just create the class LocationModel:

@interface LocationModel : JSONModel

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

@end
0

You are just missing the @protocol declaration for your LocationModel I think

#import "JSONModel.h"

@protocol LocationModel;
@interface LocationModel : JSONModel

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

@end
Clad Clad
  • 2,653
  • 1
  • 20
  • 32