0
NSNumber *a;

for(NSDictionary *item in[res valueForKey:@"snapshot"])
{
a=[item valueForKey:@"lat"];
NSLog(@"%@",a);
b=[item valueForKey:@"lng"];
NSLog(@"%@",b);
}

写在控制台上: ("29.13","29.38","29.31","29.30","29.43" ) ("94.13","94.38","93.30","94.58","94.34" )`

我怎样才能让每个值转换为双精度值?我想从此输出中获取每个纬度和经度对。

4

1 回答 1

1

根据您的说法,NSLog您从中获得的价值valueForKey:NSArrays,不是NSNumber。所以简单地通过这些数组。

for(NSDictionary *item in[res valueForKey:@"snapshot"])
{
    NSArray* latitudesList  = [item valueForKey:@"lat"];
    NSArray* longitudesList = [item valueForKey:@"lng"];
    NSInteger idx = 0;
    NSInteger nb = MIN( latitudesList.count , longitudesList.count );
    for(NSInteger idx = 0; idx < nb; ++idx)
    {
      double lat = [[latitudesList  objectAtIndex:idx] doubleValue];
      double lng = [[longitudesList objectAtIndex:idx] doubleValue];
      NSLog(@"Pair #%d = { %f , %f }", idx, lat, lng);
    }
}
于 2012-10-08T22:52:26.433 回答