gpt4 book ai didi

iOS : JSONModel : NSInvalidArgumentException

转载 作者:行者123 更新时间:2023-11-29 02:03:55 25 4
gpt4 key购买 nike

我有这个 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 解析此 json https://github.com/icanzilb/JSONModel

解析此代码

self.categoriesModels = [CategoryModel arrayOfModelsFromDictionaries: [results objectForKey:@"data"]];

并尝试访问嵌套的 json

categoryModel.subCategories

我收到这个错误

-[CategoryModel subCategories]: unrecognized selector sent to instance 0x17404b910 2015-05-03 20:38:15.019 AkshefFeen[2268:786267] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategoryModel subCategories]: unrecognized selector sent to instance 0x17404b910' * First throw call stack: (0x185fb42d8 0x1977800e4 0x185fbb3a4 0x185fb8154 0x185ebaccc 0x100027608 0x18ab1d474 0x18abd7790 0x18aa78240 0x18a9e86ec 0x185f6c2a4 0x185f69230 0x185f69610 0x185e952d4 0x18f6b36fc 0x18aa5afac 0x10002d220 0x197dfea08) libc++abi.dylib: terminating with uncaught exception of type 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:可能有2个可能的原因:1. 这可能是因为您的任何 JSONModel 类中存在 @synthesize 关键字。

  1. 这可能是由于父对象和子对象之间的命名相同所致。

请参阅此链接以了解 JSONModel 中的首选命名约定:Click here

或者您可以在这里提出相同的问题,您将得到官方答复或解决方案:Click Here

关于iOS : JSONModel : NSInvalidArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30018524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com