我正在使用JSONModel来处理JSON Api,现在却无法解析字典词典。
{
"locations": {
"one": {
"displayName": "Name One",
"description": "Description One"
},
"two": {
"displayName": "Name Two",
"description": "Description Two"
}
}
}
在我的例子中,我需要键“one”和“two”及其内容,所以我想到这样的事情
@protocol BaseDataModel;
@interface BaseDataModel : JSONModel
@property (nonatomic) NSDictionary<NSString *, LocationModel> *locations;
@end
但这不起作用,因为LocationModel
不是Objective-C类型。
答案 0 :(得分:1)
您应该只创建LocationModel类:
@interface LocationModel : JSONModel
@property (nonatomic) NSString * displayName;
@property (nonatomic) NSString * description;
@end
答案 1 :(得分:0)
您只是错过了LocationModel
我认为
#import "JSONModel.h"
@protocol LocationModel;
@interface LocationModel : JSONModel
@property (nonatomic, retain) NSString *displayName;
@property (nonatomic, retain) NSString *description;
@end