我有这个json数据
{"data": [{"id": 3,"nameAr": "Test","nameEn": "Test","active": 1,
"subCategories": [{"id": 27,"nameAr": "Test",
"nameEn": "Test","active": 0,
"sections": [{"id": 53,"nameAr": "Test",
"nameEn": "Test","active": 0},
{"id": 52,"nameAr": "Test","nameEn": "Test","active": 0
}]}]}],"code": "1001","message": "success"
}当使用JSONModel https://github.com/icanzilb/JSONModel解析此json时
解析此代码的代码
self.categoriesModels = [CategoryModel arrayOfModelsFromDictionaries: [results objectForKey:@"data"]];并试图访问嵌套的json
categoryModel.subCategories我犯了这个错误
-CategoryModel subCategories:未识别的选择器发送到实例0x17404b910 2015-05-03 20:38:15.019 AkshefFeen2268:786267 *终止应用程序由于未被识别的异常“NSInvalidArgumentException”,原因是:‘-分级模式subCategories:未识别的选择器发送给实例0x17404b910’*第一次抛出堆栈:(0x185fb42d8 0x1977800e4 0xfbb3a4 0x185fb8154 0x185ebaccc 0x27608 0x18ab174 0x18abd7790 0xa78a240xa240x18a18a604 0x18abd9ec0fx6xc4x4x6fx10)
我的模特
1-类别模型.h
#import "JSONModel.h"
#import "SubCategoryModel.h"
@protocol CategoryModel
@end
@interface CategoryModel : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* nameAr;
@property (strong, nonatomic) NSString* nameEn;
@property (assign, nonatomic) int active;
@property (strong, nonatomic) NSArray<SubCategoryModel>* subCategories;
@end2-次级类别模型.h
@protocol SubCategoryModel
@end
@interface SubCategoryModel : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* nameAr;
@property (strong, nonatomic) NSString* nameEn;
@property (assign, nonatomic) int active;
@property (strong, nonatomic) NSArray<SectionModel,Optional>* subCategories;
@end3-SectionModel.h
#import "JSONModel.h"
@protocol SectionModel
@end
@interface SectionModel : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* nameAr;
@property (strong, nonatomic) NSString* nameEn;
@property (assign, nonatomic) int active;
@end为什么我会得到这个错误,以及如何解决它?
https://stackoverflow.com/questions/30018524
复制相似问题