0

我正在尝试从我的 Web 服务 API 中提取数据并解析收到的 JSON ......我一直在学习 RestKit 教程,但我找不到任何关于发布请求的信息!

现在我有这个代码:

-(void) loadPerformers
{
// Create our request mapping
RKObjectMapping* requestMapping = [RKObjectMapping mappingForClass:[JsonOperationModel class]];
[requestMapping addAttributeMappingsFromArray:@[@"RequestType"]];

// Create our data mapping
RKObjectMapping* dataMapping = [RKObjectMapping mappingForClass:[DataModel class] ];
[dataMapping addAttributeMappingsFromArray:@[@"Status"]];

// Create our performer mapping
RKObjectMapping* performerMapping = [RKObjectMapping mappingForClass:[PerformerModel class] ];
[performerMapping addAttributeMappingsFromArray:@[@"IdPerformer", @"Name", @"Rate",
                                                  @"IsInWatch", @"Rating", @"PictureUrl", @"LastModifiedDate"]];

// Create our talent mapping
RKObjectMapping* talentMapping = [RKObjectMapping mappingForClass:[DataModel class] ];
[talentMapping addAttributeMappingsFromArray:@[@"Id", @"Value"]];

// Define the relationship mapping with request -> data
[requestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"data"
                                                                               toKeyPath:@"data"
                                                                             withMapping:dataMapping]];
// Define the relationship mapping with data -> performers
[requestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Performers"
                                                                               toKeyPath:@"Performers"
                                                                             withMapping:performerMapping]];
// Define the relationship mapping with performer -> talent
[requestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Talents"
                                                                               toKeyPath:@"Talents"
                                                                             withMapping:talentMapping]];

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:JsonOperationMapping pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

NSURL *URL = [NSURL URLWithString:@"http://10.10.5.106:8089/Mobile/Default.ashx"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor]];
[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    RKLogInfo(@"result: %@", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    RKLogError(@"Operation failed with error: %@", error);
}];

[objectRequestOperation start];
}

这是 RestKit 官方教程的示例,根据我的 json 修改为我的需要。但是如何调整这个示例以将 JSON 字符串发送到 URL,然后获取服务器 anwser?

我找不到任何相关信息,并且我的每个服务器响应都需要通过 JSON 字符串发送一些客户端信息,然后才能将响应发送回客户端。(它不仅像我当前的示例那样从 URL 中获取!)

感谢您对此的任何意见!

4

0 回答 0