我有这个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子类别]:无法识别的选择器已发送到实例0x17404b910
2015-05-03 20:38:15.019 AkshefFeen [2268:786267] *由于未捕获的异常'NSInvalidArgumentException'终止了应用程序,原因:'-[CategoryModel subCategories]:无法识别的选择器已发送至实例0x17404b910'
*首先抛出调用堆栈:
(0x185fb42d8 0x1977800e4 0x185fbb3a4 0x185fb8154 0x185ebaccc 0x100027608 0x18ab1d474 0x18abd7790 0x18aa78240 0x18a9e86ec 0x185f6c2a4 0x185f69230 0x185f69610 0x18x952d197a 036
libc ++ abi.dylib:以NSException类型的未捕获异常终止
我的模特儿
1-CategoryModel.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;
@end
2-SubCategoryModel.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;
@end
3-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
为什么会出现此错误,以及如何解决?
最佳答案
@ahmed Shoeib:
可能有两个可能的原因:
1.可能是由于任何JSONModel类中的@synthesize关键字。
这可能是由于父对象和子对象之间的命名相同。
请参考此链接以获取JSONModel中的首选命名约定:Click here
或者,您也可以在此处提出同样的问题,然后获得官方答复或解决方案:Click Here