0

I've this json Data

{"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"
}

While parsing this json Using JSONModel https://github.com/icanzilb/JSONModel

The code to parse this

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

And trying to access nested json

categoryModel.subCategories

I got this error

-[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

My Models

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

Why did I get this error, and how to solve it?

Anthon
  • 69,918
  • 32
  • 186
  • 246
ahmed Shoeib
  • 254
  • 6
  • 22

1 Answers1

1

@ahmed Shoeib : There may be 2 posssible reason: 1. It may be because of the @synthesize keyword in any of your JSONModel class.

  1. This may be due to same naming between parent object and child object.

Please refer this link for preferred naming conventions in JSONModel: Click here

Or you can raise issue for the same here, and you'll get official answer or resolution: Click Here

Milan Manwar
  • 374
  • 3
  • 10
  • Did you check that changing this keyword or changing the naming would solve this question by using JSONModel? Also be sure to write the relevant information from the link here, as in the future the link may be obsolete. to downvoter: please write why you have downvoted so user can learn :) – David Aug 11 '15 at 13:59
  • @DavidAnderton I faced synthesize keyword issue and same naming issue during my implementation, so i tries to help user with above possible resolution. However he can opt for official answer. And for the links, i'll take care from next time. Thanks man..!! And for the downvoter, I dont know why someone downvoted it. – Milan Manwar Aug 12 '15 at 08:53