0

iam using restKit, to send and receive data from server... iam getting back

{
    "request":"globalUpdate",
    "updateRevision":2,
    "updatedObjects":{
        "users":[
            {
                id:"someid1",
                name:"somename"
            },
            {
                id:"someid2",
                name:"somename2",
            }
        ]
    }
}

i want to use

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:nil usingBlock:^(RKObjectLoader * loader){)];

to load only objects inside updatedObjects into CoreData and request, updateRevision into NSDictionary

so in

loader.onDidLoadObjects = ^(NSArray *objects) {    

}

the first object is the Dictionary and the later one are CoreData

4

1 回答 1

0

好吧,这取决于您选择哪个对象用于核心数据以及哪个对象用于您自己的目的。RKObjectLoader 还提供了 onDidLoadResponse 块,它引用了您可以自己使用的响应。

[myobjectManager loadObjectsAtResourcePath:resourcePath usingBlock:^(RKObjectLoader *loader) {
        loader.mappingProvider = [RKObjectMappingProvider mappingProviderUsingBlock:^(RKObjectMappingProvider *provider) {
            [provider setObjectMapping:[MyClass mapping] forKeyPath:@"updatedObjects"];
            loader.onDidLoadObjects = ^(NSArray *objects){

            };
            loader.onDidLoadResponse = ^(RKResponse *response){
               // NSData * data  = [response data];
                id object = [response parsedBody:nil];
               // now parse the data yourself which will give you
               // the entire json in NSData for and parse it,
               // extract the component you need
            };
            loader.onDidFailWithError = ^(NSError *error){

            };
        }];
    }];
于 2012-11-21T22:57:24.230 回答