0

I use JSONModel to hold my app datasource, and use -(id)initWithArray:(NSArray *)array modelClass:(Class)cls generated an JSONModelArray, now I want to do some search stuff like enumerateObjectsUsingBlock: method does. But I found that JSONModelArray is not inherited from NSArray.

So, how can I do this?

Allen
  • 6,745
  • 5
  • 41
  • 59
  • 1
    As it says, it's another object which is constructed with an array. Since this is an external library modifying the original code is not a good idea as well. Just try to implement a simple category for the base class. It will do the work. – erenkabakci Oct 12 '15 at 08:47

1 Answers1

0

Try use BWJSONMatcher to convert json string to a NSArray.

For example, your json string seems like :

[{"name":"Arron","age":20,"grade":2},{"name":"Burrows","age":21,"grade":2}]

All you have to do is declare your own data model:

@interface Student : NSObject

@property (nonatomic, strong) NSString *name;
@property (nonatomic, assign) NSInteger age;
@property (nonatomic, assign) NSInteger grade;

@end

BWJSONMatcher will help you convert it to a NSArray in a very neat way:

NSArray *students = [BWJSONMatcher matchJSON:jsonString withClass:[Student class]];
Burrows Wang
  • 249
  • 1
  • 7