jsonparsing

jsonparsing

-(void)searchGooglePhotos
{   

    Arr_Lat=[[NSMutableArray alloc] init];
    Arr_title=[[NSMutableArray alloc] init];
    Arr_address=[[NSMutableArray alloc]init];
    Arr_Long=[[NSMutableArray alloc]init];

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",strSearch];
    NSError *error=nil;
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:&error];
    NSArray *listItems = [locationString componentsSeparatedByString:@","];


    if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"])
    {
        latitude = [[listItems objectAtIndex:2] doubleValue];
        longitude = [[listItems objectAtIndex:3] doubleValue];
    }

    NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:@"http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=atm&rsz=8&sll=%f,%f&radius=1000&output=json", latitude,longitude]];

    NSURLRequest *request2 = [NSURLRequest requestWithURL:url1];

    NSData *responseDataValue2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:nil error:nil];

    NSString *jsonString2 = [[NSString alloc] initWithData:responseDataValue2 encoding:NSUTF8StringEncoding];

    NSDictionary *main=[jsonString2 JSONValue];

    NSLog(@"main dic--%@",main);

    Arr_title = [[[main valueForKey:@"responseData"] valueForKey:@"results"]valueForKey:@"titleNoFormatting"];
    Arr_address=[[[main valueForKey:@"responseData"]valueForKey:@"results"]valueForKey:@"addressLines"];
    Arr_Lat=[[[main valueForKey:@"responseData"]valueForKey:@"results"]valueForKey:@"lat"];
    Arr_Long=[[[main valueForKey:@"responseData"]valueForKey:@"results"]valueForKey:@"lng"];

    [Arr_title retain];
    [Arr_address retain];
    [Arr_Lat retain];
    [Arr_Long retain];



    [tbl_place reloadData];

}

-(void)fireWebService { Arr_Lat=[[NSMutableArray alloc] init]; Arr_title=[[NSMutableArray alloc] init]; Arr_Long=[[NSMutableArray alloc]init]; Arr_address=[[NSMutableArray alloc]init];

NSString *urlString = [NSString stringWithFormat:@"http://ajax.googleapis.com/ajax/services/search/local?v=1.0&rsz=8&q=atm&sll=%f,%f&radius=100&output=json",appDel.curr_lat,appDel.curr_long];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL

URLWithString:urlString]];

NSData *responseDataValue = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSString *jsonString = [[[NSString alloc] initWithData:responseDataValue encoding:NSUTF8StringEncoding] autorelease];

NSDictionary *main = [jsonString JSONValue];

Arr_title = [[[[main valueForKey:@"responseData"]

valueForKey:@"results"]valueForKey:@"titleNoFormatting"] copy]; Arr_address=[[[[main valueForKey:@"responseData"]valueForKey:@"results"]valueForKey:@"addressLines"] copy]; Arr_Lat=[[[[main valueForKey:@"responseData"]valueForKey:@"results"]valueForKey:@"lat"] copy]; Arr_Long=[[[[main valueForKey:@"responseData"]valueForKey:@"results"]valueForKey:@"lng"] copy];

[Arr_title retain];

[tbl_nearplace reloadData];

}

View Answers









Related Tutorials/Questions & Answers:
jsonparsing
?q=%@&output=csv",strSearch]; NSError *error=nil; NSString...?v=1.0&q=atm&rsz=8&sll=%f,%f&radius=1000&output=json...://ajax.googleapis.com/ajax/services/search/local?v=1.0&rsz=8&q=atm&sll=%f,%f&

Ads