1

restkitオブジェクトマッピングを使用して応答jsonデータをマッピングして保存しようとしています。残念ながら、応答データをマッピングできません。データベースを表示すると、データが保存されていますが、次のメッセージが表示されてクラッシュします。 このクラスは、キーのキー値コーディングに準拠していません。

出力応答

{
    "users": [
        {
            "id": "123456",
            "ne": "JohnSmith",
            "el": "example@example.com",
            "dob": "1985/02/04",
            "profile": {
                "id": "654321",
                "ht": "170cm",
                "wt": "70kg"
            }
        }
    ]
}

私はこのようなマッピングを使用しています

 RKManagedObjectMapping *userProfileMapping = [RKManagedObjectMapping mappingForClass:[GHSUser class] inManagedObjectStore:manager.objectStore];
    [userProfileMapping mapKeyPath:@"id" toAttribute:@"userId"];
    [userProfileMapping mapKeyPath:@"ne" toAttribute:@"name"];    
    [userProfileMapping mapKeyPath:@"el" toAttribute:@"email"];
    [userProfileMapping mapKeyPath:@"dob" toAttribute:@"dob"];

 RKManagedObjectMapping *standardProfileMapping = [RKManagedObjectMapping mappingForClass:[GHSProfile class] inManagedObjectStore:manager.objectStore];

    [standardProfileMapping mapKeyPath:@"id" toAttribute:@"userId"];
    [standardProfileMapping mapKeyPath:@"ht" toAttribute:@"height"];
    [standardProfileMapping mapKeyPath:@"wt" toAttribute:@"weight"];

[manager.mappingProvider setMapping:standardProfileMapping forKeyPath:@"users.profile"];

//ここkeypath(users.profile)でクラッシュしますが、プロファイルの詳細がdbに挿入されています。キーパスをプロファイルに変更すると、クラッシュは発生しませんが、プロファイルの詳細がデータベースに挿入されません。

  [userProfileMapping mapRelationship:@"users" withMapping:standardProfileMapping];

エラーメッセージ:

*キャッチされなかった例外'NSUnknownKeyException'が原因でアプリを終了しています。理由:'[<_ NSObjectID_48_2 0x888a8d0> setValue:forUndefinedKey:]:このクラスはキープロファイルのキー値コーディングに準拠していません。

4

1 に答える 1

1

これは、usersパラメーターがNSDictionaryではなくNSArrayであるためです。users.profileどちらを使うべきかわからない。

同じ行を変更したい:

[manager.mappingProvider setMapping:standardProfileMapping forKeyPath:@"users.profile"];

に:

[manager.mappingProvider setMapping:userProfileMapping forKeyPath:@"users"];

次の行をuserProfileMappingに追加します。

[userProfileMapping mapKeyPath: @"profile" toRelationship: @"profile" withMapping: standardProfileMapping]
于 2012-08-22T12:58:15.437 に答える