如何在iOS中解析这种类型的链接?

时间:2014-06-05 10:56:41

标签: ios objective-c

如何解析以下链接: -         http://www.cbapcertprep.com/service/index.php?/Download_vehicletrack/DownloadTrackData/35170

如何在表格中显示经度和纬度数据?

2 个答案:

答案 0 :(得分:0)

只需使用JSON解析即可:

for(NSDictionary *dict in dataArray)
{
    NSLog(@"latitude %@",[dict objectForKey:@"latitude"]);
    NSLog(@"longitude %@",[dict objectForKey:@"longitude"]);
}

答案 1 :(得分:0)

假设这是你的.m文件

@interface searchResultsViewController ()
{
NSMutableArray *getlot, *getlong;
 }
 @end
在您的视图中

加载了

-(void)viewDidLoad
{
getlong =[[NSMutableArray alloc]init];
getlot =[[NSMutableArray alloc]init];
[self getdails];     //this get the longitude and latitude fr
}

-(void) getdails
{
   NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.cbapcertprep.com/service/index.php?/Download_vehicletrack/DownloadTrackData/35170"]];

[request setHTTPMethod:@"GET"];

[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];

NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];

for (int i=0; i<[jsonArray count]; i++)
{
    NSString *strlong=[[jsonArray objectAtIndex:i]objectForKey:@"longitude"];
     NSString *strlat=[[jsonArray objectAtIndex:i]objectForKey:@"latitude"];

   [getlong addObject: strlong];
   [getlot addObject: strlat];

}
[self.yourtableview reloaddata];
}


 #pragma mark - tablevie data source

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

 return [getlong count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;


}
 cell.textlabel.text=[getlot objectAtIndex:indexPath.row];
 cell.detailTextLabel.text=[getlong objectAtIndex:indexPath.row];

return cell;

  }