-1

我有以下内容NSArray

(
        {
        geometry =         {
            location =             {
                lat = "37.789632";
                lng = "-122.417004";
            };
        };
        icon = "http://maps.gstatic.com/mapfiles/place_api/icons/doctor-71.png";
  vicinity = "900 Hyde Street, San Francisco";
    },
        {
        geometry =         {
            location =             {
                lat = "37.794774";
                lng = "-122.398941";
            };
        };
        icon = "http://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png";
 vicinity = "2 Embarcadero Center, San Francisco";
}
)

从这里我怎样才能从每个索引中获取latitude和?longitude

4

2 回答 2

7

你甚至没有试着去想这个??我会帮你的乐趣,但帮助你自己的人

NSArray *values = ...;
for (NSDictionary *geometry in values) {
    NSDictionary *loc = [geometry valueForKey:@"location"];
    if (loc) {
        NSNumber *lat = [loc valueForKey:@"lat"];
        NSNumber *lng = [loc valueForKey:@"lng"];
        if (lat && lng) {
            // do whatever
        }
    }
}

编辑:也许是这样

NSArray *values = ...;
for (NSDictionary *item in values) {
    NSDictionary *geo = [item valueForKey:@"geometry"];
    if (geo) {
        NSDictionary *loc = [geometry valueForKey:@"location"];
        if (loc) {
            NSNumber *lat = [loc valueForKey:@"lat"];
            NSNumber *lng = [loc valueForKey:@"lng"];
            if (lat && lng) {
                // do whatever
            }
        }
    }
}
于 2012-12-24T11:42:11.103 回答
2
for (int i=0 ; i<[parsedAry count] ; i++) {

    NSMutableDictionary * location = [[[parsedAry objectAtIndex:i]objectForKey:@"geometry"]objectForKey:@"location"];
    NSString * lat = [location objectForKey:"lat"];
    NSString * lng = [location objectForKey:"lng"]; 
    [latAry addObject:lat];
    [LongAry addObject:lng];


}

您必须创建和分配 latAry 和 longAry

于 2012-12-24T11:49:24.963 回答