brunow/BWObjectMapping

Question: Map objects of dictionaries

Closed this issue · 1 comments

I try to map some JSON data to core data. How would I manage to map a JSON structure like this? I have a different naming in my attributes. like "objectId", "name", "info", "phone".
[

{
"Id": 2,
"Name": “James”
"Description": “Pilot”,
"Phone": “54 34 45 22”
},

{
"Id": 3,
"Name": “Lucy”
"Description": “”,
"Phone": “67 45 45 22”
}
]
Thank you in advance

It's really simple:

[BWObjectMapping mappingForObject:[User class] block:^(BWObjectMapping *mapping) {
[mapping mapPrimaryKeyAttribute:@"Id" toAttribute:@"objectId"];
[mapping mapKeyPath:@"Name" toAttribute:@"name"];
[mapping mapKeyPath:@"Description" toAttribute:@"info"];

[[BWObjectMapper shared] registerMapping:mapping];

}];

NSArray *objects = [[BWObjectMapper shared] objectsFromJSON:JSON withObjectClass:[User class]];