我想問一下這裏的東西。我已經映射了該對象並將其添加到RKResponseDescriptor中,它可以工作,但這裏存在問題。當來自JSON的數據不同時,它不映射到已經創建的對象,我只是意識到它沒有很好的映射。addResponseDescriptors不止一個
// Setup our object mappings
RKObjectMapping *applicationMapping = [RKObjectMapping mappingForClass:[ApplicationSettings class]];
[applicationMapping addAttributeMappingsFromDictionary:@{
@"filterRead" : @"filterRead",
@"filterUserComments" : @"filterUserComments"
}];
RKObjectMapping *categoryMapping = [RKObjectMapping mappingForClass:[Category class]];
[categoryMapping addAttributeMappingsFromDictionary:@{
@"id" : @"categoryID",
@"title" : @"title",
@"slug" : @"slug"
}];
RKObjectMapping *commentMapping = [RKObjectMapping mappingForClass:[Comment class]];
commentMapping.forceCollectionMapping = YES;
[commentMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"comments"];
[categoryMapping addAttributeMappingsFromDictionary:@{
@"(coments).id" : @"commentID",
@"(comments).date" : @"createdDate",
@"(comments).content" : @"comment"
}];
RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[Error class]];
[errorMapping addAttributeMappingsFromDictionary:@{
@"error" : @"error",
@"status" : @"status"
}];
RKObjectMapping *postMapping = [RKObjectMapping mappingForClass:[Post class]];
postMapping.forceCollectionMapping = YES;
[postMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"posts"];
[errorMapping addAttributeMappingsFromDictionary:@{
@"id" : @"postID",
@"title" : @"title",
@"content" : @"content",
@"date" : @"createdDate",
@"modified" : @"modifiedDate"
}];
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping addAttributeMappingsFromDictionary:@{
@"nonce" : @"nonce",
@"cookie" : @"cookie",
@"username" : @"userName",
@"email" : @"email"
}];
// Register our mappings with the provider using a response descriptor
RKResponseDescriptor *userResponse = [RKResponseDescriptor responseDescriptorWithMapping:userMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *applicationResponse = [RKResponseDescriptor responseDescriptorWithMapping:applicationMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *categoryResponse = [RKResponseDescriptor responseDescriptorWithMapping:categoryMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *commentResponse = [RKResponseDescriptor responseDescriptorWithMapping:commentMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *errorResponse = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *postResponse = [RKResponseDescriptor responseDescriptorWithMapping:postMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
[objectManager addResponseDescriptorsFromArray:
@[
applicationResponse,
categoryResponse,
commentResponse,
userResponse,
postResponse,
errorResponse
]] ;
編輯號1:
[objectManager addResponseDescriptorsFromArray:
@[
applicationResponse,
categoryResponse,
commentResponse,
errorResponse,
postResponse,
userResponse
]] ;
爲這一個,爲用戶的JSON數據可以被映射,但不爲其他。我的意思是我們可以如何映射對象?因爲我改變了responseDescriptors的順序,它只是映射底部的對象。
對不起我的英文不好之前
你是說當你第二次下載原始對象時沒有得到更新? – Wain 2013-04-28 07:27:46
我已經編輯了一些信息,我希望它有用 – maharprasetio 2013-04-28 08:40:16