0

I have got entities in core data with one to many relationship. How can I convert data in my entities to json string and populate core data entities with json string once it is created?

Any help would be greatly appreciated...

Shahrukh Malik
  • 242
  • 2
  • 15

1 Answers1

1

for core data to json:

fetch the data from your coredata according to your requirements, & then converts it into json.

visit this link to core data to json also see this one

for json to core data

1)convert JSON to native Cocoa data types (NSDictionary and NSArray)
2)convert NS* into Core Data object

that means you can retrieve your json data into any array or any object & then insert that object or data into core data.

get data from json like this

NSMutableArray *json = (NSMutableArray* )[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&err];
    Book.name = [[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"name"];
        Book.ID = [NSNumber numberWithInt:[[[[json valueForKey:@"boxesDetail"] objectAtIndex:i] valueForKey:@"number"] intValue]];

now insert this Book data into core data

Community
  • 1
  • 1
Ravindra Bagale
  • 17,226
  • 9
  • 43
  • 70