Tôi có một số khó khăn khi ánh xạ một mảng JSON thành RestKit. Đây là hình thức của tệp JSON:Làm thế nào để ánh xạ các mảng JSON trong RestKit
{"issuelist":[
{
"issue":[
{
"id":1,
"beschreibung":"",
"name":"Test1"
},
{
"id":2,
"beschreibung":"",
"name":"Test2"
}
]
}
]}
Tôi quan tâm đến mảng "vấn đề". Đây là bản đồ của tôi cho một vấn đề duy nhất:
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[self class] usingBlock:^(RKObjectMapping *mapping) {
[mapping mapAttributes:@"name", @"beschreibung", nil];
[mapping mapKeyPathsToAttributes:
@"id", @"identifier",
nil];
}];
Và đây là làm thế nào tôi thiết lập ObjectMapping tôi
RKObjectMappingProvider *omp = [RKObjectManager sharedManager].mappingProvider;
RKObjectMapping *issueMapping = [Issue mapping];
[omp addObjectMapping:issueMapping];
[omp setObjectMapping:issueMapping forKeyPath:@"issuelist.issue"];
Thật không may này không hoạt động. Tôi nhận được kết quả nhật ký như sau:
T restkit.object_mapping:RKObjectMappingOperation.m:152 Found transformable value at keyPath 'name'. Transforming from type '__NSArrayI' to 'NSString' W restkit.object_mapping:RKObjectMappingOperation.m:232 Failed transformation of value at keyPath 'name'. No strategy for transforming from '__NSArrayI' to 'NSString' T restkit.object_mapping:RKObjectMappingOperation.m:339 Skipped mapping of attribute value from keyPath 'name to keyPath 'name' -- value is unchanged ((null)) T restkit.object_mapping:RKObjectMappingOperation.m:322 Mapping attribute value keyPath 'beschreibung' to 'beschreibung' T restkit.object_mapping:RKObjectMappingOperation.m:152 Found transformable value at keyPath 'beschreibung'. Transforming from type '__NSArrayI' to 'NSString' W restkit.object_mapping:RKObjectMappingOperation.m:232 Failed transformation of value at keyPath 'beschreibung'. No strategy for transforming from '__NSArrayI' to 'NSString' T restkit.object_mapping:RKObjectMappingOperation.m:339 Skipped mapping of attribute value from keyPath 'beschreibung to keyPath 'beschreibung' -- value is unchanged ((null)) T restkit.object_mapping:RKObjectMappingOperation.m:322 Mapping attribute value keyPath 'id' to 'identifier' T restkit.object_mapping:RKObjectMappingOperation.m:152 Found transformable value at keyPath 'id'. Transforming from type '__NSArrayI' to 'NSString' W restkit.object_mapping:RKObjectMappingOperation.m:232 Failed transformation of value at keyPath 'id'. No strategy for transforming from '__NSArrayI' to 'NSString' T restkit.object_mapping:RKObjectMappingOperation.m:339 Skipped mapping of attribute value from keyPath 'id to keyPath 'identifier' -- value is unchanged ((null)) D restkit.object_mapping:RKObjectMappingOperation.m:624 Finished mapping operation successfully...
Có vẻ như RestKit đang cố gắng ánh xạ toàn bộ arry trong một Vấn đề thay vì tạo một loạt vấn đề. Làm cách nào để thay đổi ánh xạ của tôi để sửa lỗi này?
Cảm ơn sự giúp đỡ của bạn!
Cảm ơn! Điều đó rất hữu ích! – thalador