Q:

The Google Distance Matrix APi (JSON PARSING)

i am new programmer. and i am using Google Distance Matrix API. I am first time using JSON . i use the Following  but can't get response from server.. please give me few lines code for use JSON and fetch the distance in kilometer between two places.
http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=fr-FR&sensor=false
Thanks
when i use the following API i receive the response
- (void)viewDidLoad  {

    [super viewDidLoad]; 

    NSLog(@"viewdidload");
    responseData = [[NSMutableData data] retain]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:
                             [NSURL URLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];

  }

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{

    NSLog(@"didReceiveResponse");
   [responseData setLength:0];

  }

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

 {        
    [responseData appendData:data]; 
 }

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{    
    NSLog(@"didFailWithError");
    label.text = [NSString stringWithFormat:@"Connection failed: %@",
                                            [error description]];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

 {
    NSLog(@"connectionDidFinishLoading");   
    NSString* newStr = [[NSString alloc] initWithData:receivedData
                                             encoding:NSUTF8StringEncoding];
    [self handleResponce:newStr];
   // NSLog(@"%@",newStr);
 }

-(void)handleResponce:(NSString *)data

{
    NSLog(@"receive data is --------->%@",receiveData);
}

A:

What exactly is your problem?

Fetching the data?
Or parsing the JSON?

-(void)viewDidLoad{
    [super viewDidLoad];
    NSLog(@"viewdidload");  
    responseData = [[NSMutableData alloc] init];  
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC%7CSeattle&destinations=San+Francisco%7CVictoria+BC&mode=bicycling&language=fr-FR&sensor=false"]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"didReceiveResponse");
    [responseData setLength:0];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"didFailWithError");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    NSLog(@"connectionDidFinishLoading");
    NSString* newStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [self handleResponse:newStr]; // NSLog(@"%@",newStr);
}
-(void)handleResponse:(NSString *)string{
    NSLog(@"responseData data is --------->%@",string);
}

Try this. You sometimes referred to responceData, and sometimes to receiveData. I fixed that and the name of the method. Plus you were trying to log the responseData and not the String.

