我使用Restkit 0.20.x來映射對象從JSON像如何通過RestKit 0.20.x與結構複雜JSON
{
"d":{
"results":[
{
"Web":[
"key1":"value1",
"key2":"value2"
],
"Image":[
"key1":"value1",
"key2":"value2"
],
},
],
},
}
我的主要目的是管理「網絡」和「圖片」鍵映射對象。 我試圖映射對象,但卡在「結果」鍵(鍵「結果」的值是隻有一個元素作爲字典的數組)。 如何使用RestKit在我的情況下,映射對象?
我無法實現:
WFSD.h
@interface WFSD : NSObject
@property (nonatomic, strong) WFSResults *results;
@end
WFSResults.h
@interface WFSResults : NSObject
@property (nonatomic, strong) WFSResult *result;
@end
WFSResult.h
@interface WFSResult : NSObject
@property (nonatomic, strong) WFSWeb *web;
@property (nonatomic, strong) WFSImage *image;
@end
MyController.m
RKObjectMapping* dMapping = [RKObjectMapping mappingForClass:[WFSD class]];
RKObjectMapping* resultsMapping = [RKObjectMapping mappingForClass:[WFSResults class]];
RKRelationshipMapping* rsMapping1 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"results" toKeyPath:@"results" withMapping:resultsMapping];
[dMapping addPropertyMapping:rsMapping1];
RKObjectMapping* resultMapping = [RKObjectMapping mappingForClass:[WFSResult class]];
[resultsMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:nil toKeyPath:@"result" withMapping:resultMapping]];
RKRelationshipMapping* rsMapping2 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Image" toKeyPath:@"Image" withMapping:imageMapping];
[resultMapping addPropertyMapping:rsMapping2];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dMapping
pathPattern:nil
keyPath:@"d"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
那你嘗試,以及如何你想存儲數據?顯示你的映射和數據結構。 – Wain
我編輯了我的失敗工具。你有什麼建議嗎 ? –