I have struggled so much to find a solution and a good tutorial that teach Object Mapping feature of Restkit. However, the tutorial from the GITHUB repo is very unclear.
This the JSON I receive of making a GET call to http://baseURL.com/contacts/
Please notice that my JSON does not have a root keypath like "ACContact", compared to other tutorials.
[{
"status":"ACTIVE",
"fax":"555-1212",
"addresses":[
{
"line1":"6 Main Street",
"line2":"",
"city":"Acton"
},
{
...
}
....(other stuff)...
}
...more similar JSONs for the other contacts...
]
I still cannot figure out how to map the array of children objects Addresses, thus I just try to map other regular property of the class:
RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURL: some_URL] ;
[[manager client] setValue:@"true" forHTTPHeaderField:@"SSLClientCipher"] ;
[[manager client] setValue:@"accept" forHTTPHeaderField:@"application/json"] ;
RKObjectMapping * contactMap = [RKObjectMapping mappingForClass:[ACContact class]] ;
[contactMap mapKeyPath:@"status" toAttribute:@"status"] ;
[contactMap mapKeyPath:@"fax" toAttribute:@"fax"] ;
[[manager mappingProvider] addObjectMapping:contactMap] ;
[manager loadObjectsAtResourcePath:@"/contacts" delegate:self] ;
This is the errors I received afterward:
restkit.object_mapping:RKObjectMapper.m:81 Adding mapping error: Could not find an object mapping for keyPath: ''
restkit.network:RKObjectLoader.m:222 Encountered errors during mapping: Could not find an object mapping for keyPath: ''
1)Can anyone please tell me what is going wrong here? Please notice that my JSON does not have a root keypath like "ACContact", compared to other tutorials.
For simple attributes like status and fax in the JSON, is there a convention for mapping the values into my Contact class's properties.
2)Furthermore, I know I can use relation ship mapping to map the child objects Addresses, but how do I do it when I declare an NSMutableArray to store the list of addresses inside the contact.
3)If everything is ok, how is it possible to create a list of contacts when parsing the entire JSON of multiple Contacts?
Thank you for your time. Brian