JSON ファイルは次のようになります。
{
"status":"success",
"result":[
{
"id":"1",
"name":"Wigwam Motel",
"latitude":34.106785,
"longitude":-117.349399,
"tag1_id":123,
"tag2_id":2,
"tag3_id":3,
"address1":"Some Place Str.",
"address2":"123",
"city":"San Francisco",
"state":"CA",
"zip":94103,
"total_photos":"4",
"total_checkins":"5",
"status":"approved",
"hero_checkin":
{
"id":12345,
"type":"photo",
"comment":"Lorm Ipsum Etc.",
"created":"2012-04-02",
"photo_name":"http://crashtestdata.sandbox.whoisstudio.com/crashtestdata.sandbox.whoisstudio.com//images/thumbs/abbotkinneymural.jpg",
"attraction":
{
"id":"12345",
"name":"Attraction 1"
},
"user":
{
"id":"1234",
"username":"john.smith",
"facebook_uid":"false",
"twitter_username":"false",
"email":"jhon.smith@example.org",
"first_name":"John",
"last_name":"Smith",
"avatar":"http://crashtestdata.sandbox.whoisstudio.com/crashtestdata.sandbox.whoisstudio.com//images/thumbs/abbotkinneymural.jpg"
}
}
},
マッピングは次のようになります。
RKManagedObjectMapping* checkInMapping = [RKManagedObjectMapping mappingForClass:[CheckIn class]
inManagedObjectStore: [RKObjectManager sharedManager].objectStore];
checkInMapping.primaryKeyAttribute = @"checkInId";
[checkInMapping mapKeyPathsToAttributes:
@"id", @"checkInId",
@"comment", @"comment",
@"facebook_share_id", @"facebookShareId",
@"photo_name", @"photoName",
@"twitter_share_id", @"twitterShareId",
@"account_id", @"accountId",
@"attraction_id", @"attractionId",
@"created", @"createdTimestamp",
@"updated", @"updatedTimestamp",
@"type", @"type",
nil];
RKManagedObjectMapping *mapping = [RKManagedObjectMapping mappingForClass:[Attraction class]
inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
mapping.primaryKeyAttribute = @"attractionId";
[mapping mapKeyPath:@"hero_checkin" toRelationship:@"heroCheckIn" withMapping:checkInMapping];
[mapping mapKeyPathsToAttributes:
@"id", @"attractionId",
@"name", @"name",
@"description", @"description",
@"longitude", @"longitude",
@"latitude", @"latitude",
@"tag1_id", @"tag1Id",
@"tag2_id", @"tag2Id",
@"tag3_id", @"tag3Id",
@"city", @"city",
@"state", @"state",
@"zip", @"zip",
@"total_photos", @"totalPhotos",
@"total_checkins", @"totalCheckIns",
@"status", @"status",
@"founder_user_id", @"founderId",
@"founder_user", @"founderUser",
@"region_id", @"regionId",
@"region", @"region",
@"region_checkin_id",@"regionCheckInId",
@"region_checkin", @"regionCheckIn",
nil];
// Just another try to map the relationship it didn't work
// [mapping mapRelationship:@"heroCheckIn" withMapping:checkInMapping];
// [[RKObjectManager sharedManager].mappingProvider setMapping:checkInMapping
// forKeyPath:@"response.hero_checkin"];
// [checkInMapping hasOne:@"heroCheckInId" withMapping:mapping];
// [checkInMapping connectRelationship:@"heroCheckIn"
// withObjectForPrimaryKeyAttribute:@"heroCheckId"];
[[RKObjectManager sharedManager].mappingProvider setObjectMapping:mapping forKeyPath:@"result"];
そして、これは私が得ているものです:
<Attraction: 0xf19d080> (entity: Attraction; id: 0xf198060 <x-coredata://4C997AF5-D806-46C8-AD32-80220D2E9D97/Attraction/p7> ; data: {
address1 = nil;
address2 = nil;
attractionId = 1;
city = "San Francisco";
founder = nil;
founderAccountId = 0;
heroCheckIn = nil;
heroCheckInId = 0;
latitude = "34.106785";
longitude = "-117.349399";
name = "Wigwam Motel";
region = nil;
regionId = 0;
state = CA;
status = approved;
tag1Id = 123;
tag2Id = 2;
tag3Id = 3;
totalCheckIns = 5;
totalPhotos = 4;
zip = 94103;
ご覧のとおり、heroCheckIn は nil です。私は多くのフォーラムを読み、ここに投稿し、RestKit のドキュメントを読んでいますが、何かが足りないようですので、助けを歓迎するか、少なくとも正しい方向への良いプッシュをお願いします。 . ところで、関係を持つ CoreData モデルと、それに応じて Attraction と CheckIn の属性を持つすべてのフィールドがあります。
前もって感謝します