现在遇到问题。谷歌搜索解决方案,但仍然无法得到任何解决方案。如果有人能帮助我,我真的很感激
基本上我使用AFNetworking库消耗OneMap API。我得到的返回数据,当我NSLog它时,:被替换为=而[被替换为(
显然,POST方法不起作用,OneMap是否只支持GET?
当我将其转换为字符串并使用UTF8进行编码时,它会以正确的格式记录,但我无法直接从字符串中检索键值吗?
以下是我用来使用它的代码片段:
- (void)getDrivingDirections:(NSArray *)coords destination:(NSArray *)dest {
NSString *destination = [dest componentsJoinedByString:@","];
NSString *currentLocation = [coords componentsJoinedByString:@","];
NSString *routeStops = [[NSString alloc]initWithFormat:@"%@;%@",currentLocation,destination];
NSString *dataURL = [[NSString alloc]initWithFormat:@"http://www.onemap.sg/API/services.svc/route/solve?token=%@&routeStops=%@",tokenString,routeStops];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:dataURL]];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
path:dataURL
parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
[MMProgressHUD dismissWithSuccess:@"Something went wrong :("];
}];
[operation start];
}
以下是返回的片段:http://pastebin.com/Sa0U0tYf(太长了,无法直接在此处发布)
谢谢!
答案 0 :(得分:1)
如果您希望返回JSON,为什么不尝试使用AFJSONRequestOperation
?响应对象将是NSDictionary
,其中包含JSON响应的内容,使用内置NSJSONSerialization
进行解析。