0

我正在尝试通过下面的代码映射 POST 响应,但是当到达 didLoadObjects 时,Restkit 正在尝试映射与我尝试 POST 相同的对象(发布 Foo 并希望它映射 Bar,但 RestKit 正在尝试映射返回 Foo)。

[self.objectManager sendObject:mySyncInstance toResourcePath:url usingBlock:^(RKObjectLoader* postLoader) {
        postLoader.delegate = aDelegate;
        postLoader.objectMapping = [self.objectManager.mappingProvider objectMappingForClass:[Bar class]];
        postLoader.method = RKRequestMethodPOST;
        postLoader.userData = kUserDefaultsAttendanceReads;
        postLoader.serializationMIMEType = RKMIMETypeJSON;
        postLoader.serializationMapping
        [postLoader setUsername:[prefs objectForKey:kCurrentUsername]];
        [postLoader setPassword:[prefs objectForKey:kCurrentPassword]];
    }];// end sendObject
4

1 回答 1

0

解决方案是设置 rootKeyPath。

myPostReturnMapping.rootKeyPath = @"persons";

"persons": [
                        { "id": "1",
                          "firstname": "hans",
                          "lastname": "maier",
                          "genre": "m"
                        },
                        { "id": "2",
                          "firstname": "michael",
                          "lastname": "schmidt",
                          "genre": "w"
                        }]
于 2012-06-20T03:43:58.980 回答