我正在尝试解析一个NSStrings
with数组,lat/long coordinates("99.999999","99.999999")
然后将其转换为array
of CLLocations
。
有没有一种NSString
方法可以帮助解决这个问题?
我从外部 REST API 中提取这些坐标,然后JSON
先将其转换为字典,然后再转换为数组,这就是我卡住的地方。
有任何想法吗 ?
谢谢!
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"connectionDidFinishLoading");
NSLog(@"Succeeded! Received %d bytes of data",[self.responseData length]);
NSError *myError = nil;
NSDictionary *jsonResult = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
// Show ALL values coming out of NSJSONSerialization
for(id key in jsonResult) {
id value = [jsonResult objectForKey:key];
NSString *keyAsString = (NSString *)key;
NSString *valueAsString = (NSString *)value;
NSLog(@"key: %@", keyAsString);
NSLog(@"value: %@", valueAsString);
}
NSArray *jsonCoordinates =[jsonResult objectForKey:@"latlng"];
for (id key in jsonCoordinates) {
//id value = [jsonCoordinates objectForKey:key];
NSString *keyAsString = (NSString *)key;
//NSString *valueAsString = (NSString *)value;
NSLog(@"key: %@", keyAsString);
//NSLog(@"value: %@", valueAsString);
}
}
日志输出:
2013-04-29 22:23:44.894 RideInfo[9271:c07] 键:(“37.473497”,“-122.213878”)2013-04-29 22:23:44.894 RideInfo[9271:c07] 键:(“37.47346” , "-122.213538")