Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Http RestKit:RKObjectManager';s postObject:mapResponseWith:delegate_Http_Rest_Post_Restkit - Fatal编程技术网

Http RestKit:RKObjectManager';s postObject:mapResponseWith:delegate

Http RestKit:RKObjectManager';s postObject:mapResponseWith:delegate,http,rest,post,restkit,Http,Rest,Post,Restkit,我想以json作为对象发送 HTTP Headers: { "Content-Length" = 24; "Content-Type" = "application/json"; } HTTP Body: {"userId":"5","mode":""}. 然后拿回一个json HTTP Headers: { "Content-Type" = "application/json"; } HTTP Body: {"insertCount":4,"offerCount":0

我想以json作为对象发送

HTTP Headers: {
    "Content-Length" = 24;
    "Content-Type" = "application/json";
}
HTTP Body: {"userId":"5","mode":""}.
然后拿回一个json

HTTP Headers: {
    "Content-Type" = "application/json";
}
HTTP Body: {"insertCount":4,"offerCount":0,"favoriteOfferCount":0,"favoriteInsertCount":0}
并将其映射到一个对象,当我遇到许多涉及路由器、对象加载器等的错误时,有人能指导我吗

我知道我必须使用RKObjectManager的postObject:mapResponseWith:delegate:


但是配置它是令人困惑的。

不要紧,我是这样做的

@interface RestKitUtil :  NSObject <RKObjectLoaderDelegate,RKRequestDelegate>
-(void)postobj;
@end


@implementation RestKitUtil

-(void)postobj{

    RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
   [RKObjectManager objectManagerWithBaseURL:@"http://10.6.10.121:80/CW_war"];

    RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[CountResultVO class]];
    [mapping mapKeyPathsToAttributes:
     @"offercount", @"offercount",
     @"insertCount", @"insertCount",
     @"favouriteOfferCount", @"favouriteOfferCount",
     @"favouriteInsertCount", @"favouriteInsertCount",
     nil];


   RKObjectRouter *router = [RKObjectManager sharedManager].router;
    [router routeClass:[BasicUserArgVo class] toResourcePath:@"/getMyOffersCount" forMethod:RKRequestMethodPOST];

    [RKObjectManager sharedManager].objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"objStore.sqlite"];

    RKObjectMapping *listMapping = [RKObjectMapping mappingForClass:[BasicUserArgVo class]];    
    [listMapping mapKeyPath:@"userId" toAttribute:@"userId"];
    [listMapping mapKeyPath:@"mode" toAttribute:@"mode"];

    [[RKObjectManager sharedManager].mappingProvider addObjectMapping:listMapping ];

    [[RKObjectManager sharedManager].mappingProvider setSerializationMapping:[listMapping inverseMapping] forClass:[BasicUserArgVo class]];

    [[RKObjectManager sharedManager] setSerializationMIMEType:RKMIMETypeJSON];
    //NSUTF8StringEncoding
    [[RKObjectManager sharedManager] setAcceptMIMEType:RKMIMETypeJSON];


    BasicUserArgVo *bvo = [[BasicUserArgVo alloc] initWithUserId:5];

    [[RKObjectManager sharedManager] postObject:bvo mapResponseWith:mapping delegate:self]; 
}


- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
    CountResultVO* cvo = [objects objectAtIndex:0];

    NSLog(@"values:%ld,%ld,%ld,%ld",[cvo offercount],[cvo insertCount],
          [cvo favouriteOfferCount],[cvo favouriteInsertCount] );
}

- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error {
    NSString *msg = [NSString stringWithFormat:@"Error: %@", [error localizedDescription]];
    NSLog(@"log : %@",msg);    
}

@end
@interface RestKitUtil:NSObject
-(void)postobj;
@结束
@实现RestKitUtil
-(无效)postobj{
RKLogConfigureByName(“RestKit/Network”,RKLogLevelTrace);
[RKObjectManager ObjectManager WithBaseURL:@”http://10.6.10.121:80/CW_war"];
RKObjectMapping*mapping=[RKObjectMappingForClass:[CountResultVO class]];
[映射MapKeyPathStoAttribute:
@“报价计数”@“报价计数”,
@“insertCount”@“insertCount”,
@“FavoriteOfferCount”@“FavoriteOfferCount”,
@“FavoriteInsertCount”@“FavoriteInsertCount”,
零];
RKObjectRouter*路由器=[RKObjectManager sharedManager]。路由器;
[路由器路由类:[BasicUserArgVo类]到源路径:@“/getMyOffersCount”formMethod:RKRequestMethodPOST];
[RKObjectManager sharedManager].objectStore=[RKManagedObjectStore objectStoreWithStoreFilename:@“objStore.sqlite”];
RKObjectMapping*listMapping=[RKObjectMappingForClass:[BasicUserArgVo类]];
[ListMappingMapKeyPath:@“userId”到属性:@“userId”];
[ListMappingMapKeyPath:@“模式”到属性:@“模式”];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:listMapping];
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:[listMapping inverseMapping]forClass:[BasicUserArgVo类]];
[[RKObjectManager sharedManager]setSerializationMIMEType:RKMIMETypeJSON];
//NSUTF8StringEncoding
[[RKObjectManager sharedManager]setAcceptMIMEType:RKMIMETypeJSON];
BasicUserArgVo*bvo=[[BasicUserArgVo alloc]initWithUserId:5];
[[RKObjectManager sharedManager]postObject:bvo mapResponseWith:mapping delegate:self];
}
-(void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)对象{
CountResultVO*cvo=[objects objectAtIndex:0];
NSLog(@“值:%ld,%ld,%ld,%ld”,[cvo offercount],[cvo insertCount],
[cvo FavoriteOfferCount],[cvo FavoriteInsertCount];
}
-(void)objectLoader:(RKObjectLoader*)objectLoader错误:(NSError*)错误{
NSString*msg=[NSString stringWithFormat:@“错误:%@,[Error LOCATIZEDDESCRIPTION]];
NSLog(@“log:%@”,msg);
}
@结束