iosobjective-cafnetworking

My return data form AFNetworking JSON is not displaying properly


I'm experiencing a problem now. Tried Googling around for solutions but still unable to get any. Would really appreciate if anyone could help me with this

Basically I'm consuming OneMap API using AFNetworking library. The return data that I get, when I NSLog it, the : is replaced with = while the [ are replaced with (.

And apparently, the POST approach doesn't work, does OneMap only support GET?

When I convert it to a string and encode it with UTF8 it logs in the proper format, but I'm unable to retrieve keyvalues from the string directly right?

Here is a snippet of the code I'm using to consume it:

-(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];
 
}

Here is a snippet of the return : http://pastebin.com/Sa0U0tYf (too long to post it here directly)


Solution

  • If you expect JSON to be returned, why don't you try to use AFJSONRequestOperation? The response object will be a NSDictionary with the contents of the JSON response, parsed with built-in NSJSONSerialization.