I have an App using core data with 3 entities with very similar attributes. The relationship is such as:
Branch ->> Menu ->> Category ->> FoodItem
Each entity has an associated class: example
I am trying to generate JSON representation of the data in sqlite database.
//gets a single menu record which has some categories and each of these have some food items
id obj = [NSArray arrayWithObject:[[DataStore singleton] getHomeMenu]];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:obj options:NSJSONWritingPrettyPrinted error:&err];
NSLog(@"JSON = %@", [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
But instead of JSON, i get a SIGABRT error.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (Menu)'
Any ideas how to fix it or how to make the entity classes (Branch, Menu etc) JSON serialization compatible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…