У меня следующая структура JSON:
{
"users":
[
{
"user_id":"000228D2-CB0D-4019-ADF9-66FE163E0BBC",
"firstname":"aFirstname",
"name":"aLastName",
"nickname":"user_nickname",
"email":"user_email",
"uri":"user_website",
"birthday":"1976-12-08 00:00:00",
"password":"49722f17a3838181cc9cf351df9d9054e465a778",
"recovery_key":"97011336-3A4C",
"language":"fr_FR",
"timezone":"Europe\/Paris",
"last_update":"0000-00-00 00:00:00",
"creation_date":"2011-11-24 15:03:50",
"status":"20"
}
,
{
"user_id":"100228D2-CB0D-4019-ADF9-66FE163E0BBC",
"firstname":"aFirstname",
"name":"aLastName",
"nickname":"user_nickname",
"email":"user_email",
"uri":"user_website",
"birthday":"1976-12-08 00:00:00",
"password":"49722f17a3838181cc9cf351df9d9054e465a778",
"recovery_key":"97011336-3A4C",
"language":"fr_FR",
"timezone":"Europe\/Paris",
"last_update":"0000-00-00 00:00:00",
"creation_date":"2011-11-24 15:03:50",
"status":"10"
}
]
}
Тогда в моем приложении для iPhone есть следующий код для обработки объектов данных json и core.
ObjectManager init:
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://json_source_url.com"];
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
NSString *databaseName = @"myDatastore.sqlite";
objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:databaseName usingSeedDatabaseName:nil managedObjectModel:nil delegate:self];
Настройка отображения объекта:
RKManagedObjectMapping* userMapping = [RKManagedObjectMapping mappingForEntityWithName:@"User"];
userMapping.primaryKeyAttribute = @"userID";
[userMapping mapKeyPathsToAttributes:@"user_id", @"userID",
@"firstname", @"firstname",
@"name", @"name",
@"nickname", @"nickname",
@"email", @"email",
@"uri", @"uri",
@"birthday", @"birthday",
@"password", @"password",
@"recovery_key", @"recoveryKey",
@"language", @"language",
@"timezone", @"timezone",
@"last_update", @"lastUpdate",
@"creation_date", @"creationDate",
@"status", @"status",
nil];
[objectManager.mappingProvider setMapping:userMapping forKeyPath:@"users"];
С этой конфигурацией она не работает. ObjectLoader не создает и не обновляет ничего в хранилище данных coreData.
Если я изменяю структуру JSON следующим образом, она работает как шарм.
[
{
"user_id":"000228D2-CB0D-4019-ADF9-66FE163E0BBC",
"firstname":"aFirstname",
"name":"aLastName",
"nickname":"user_nickname",
"email":"user_email",
"uri":"user_website",
"birthday":"1976-12-08 00:00:00",
"password":"49722f17a3838181cc9cf351df9d9054e465a778",
"recovery_key":"97011336-3A4C",
"language":"fr_FR",
"timezone":"Europe\/Paris",
"last_update":"0000-00-00 00:00:00",
"creation_date":"2011-11-24 15:03:50",
"status":"20"
}
,
{
"user_id":"100228D2-CB0D-4019-ADF9-66FE163E0BBC",
"firstname":"aFirstname",
"name":"aLastName",
"nickname":"user_nickname",
"email":"user_email",
"uri":"user_website",
"birthday":"1976-12-08 00:00:00",
"password":"49722f17a3838181cc9cf351df9d9054e465a778",
"recovery_key":"97011336-3A4C",
"language":"fr_FR",
"timezone":"Europe\/Paris",
"last_update":"0000-00-00 00:00:00",
"creation_date":"2011-11-24 15:03:50",
"status":"10"
}
]
Спасибо за вашу помощь