创建 JSONModel 时出现错误。
错误域 = JSONModelErrorDomain 代码 = 1 “无效的 JSON 数据:尝试使用 initWithDictionary 初始化 JSONModel 对象:错误:但字典参数不是 'NSDictionary'。” UserInfo=0x9bc2340 {kJSONModelKeyPath=categories.Data, NSLocalizedDescription=无效的 JSON 数据:尝试使用 initWithDictionary 初始化 JSONModel 对象:错误:但字典参数不是“NSDictionary”。}
这是我得到的回应......
{
"categories": {
"Data": [
{
"Id": 19,
"Name": "",
"Description": "",
"ImageURL": "",
"FullSizeImageUrl": "",
"ParentCategoryId": 0
}
],
"Total": 1
}
}
这是我的模型
@interface CategoryResponse : JSONModel
@property (strong, nonatomic) NSDictionary <Categories> *categories;
@end
@protocol Categories @end
@interface Categories : JSONModel
@property (assign, nonatomic) int Total;
@property (strong, nonatomic) NSArray<CategoryData> *Data;
@end
@protocol CategoryData @end
@interface CategoryData : JSONModel
@property (strong, nonatomic) NSString <Optional> *Name;
@property (strong, nonatomic) NSString <Optional> *Description;
@property (strong, nonatomic) NSString <Optional> *ImageURL;
@property (strong, nonatomic) NSString <Optional> *FullSizeImageUrl;
@property (assign, nonatomic) int Id;
@property (assign, nonatomic) int ParentCategoryId;
void (^success)(AFHTTPRequestOperation *, id) = ^(AFHTTPRequestOperation *op, id data) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError *error;
categories = [[CategoryResponse alloc] initWithString:responseString error:&error];
complete(nil, categories);
};
我意识到@property (strong, nonatomic) NSDictionary <Categories> *categories;
这不是正确的方法,但我不知道是什么。