I am trying to convert my coredata to json, I have been struggling to get this to work but have found a way that is almost working.
my code:
NSArray *keys = [[[self.form entity] attributesByName] allKeys];
NSDictionary *dict = [self.form dictionaryWithValuesForKeys:keys];
NSLog(@"dict::%@",dict);
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"json::%@",jsonString);
}
also "form" is:
@property (strong, retain) NSManagedObject *form;
This works fine except I have NSIndexSet saved in some of the coredata attributes. This poses a problem with the JSON write. Now, my indexsets do not need to be converted to json so I was wondering if there was a way to delete all indexes from the dict? or maybe there is a better way to do this I am unaware of.
here is part of the nslog of dict:
...
whereExtent = "";
wiring = (
);
wiring1 = "<NSIndexSet: 0x82b0600>(no indexes)";
wiringUpdated = "<null>";
yardFenceTrees = "<null>";
}
so in this case I want to remove "wiring1" from dict but need to be able to do it in a "dynamic" way (not using the name "wiring1" to remove it)