我正在尝试从我的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!)
感谢您的任何意见!