Dav*_*iri 2 xcode parsing json objective-c ios
我有这个:
//request stuff
NSString *searchString = [NSString stringWithFormat:@"Sydney"];
NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=%@&sensor=true&key=mykeynotyours!",searchString];
NSURL *requestURL = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:(requestURL)];
//response
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSError *jsonParsingError = nil;
NSDictionary *locationResults = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
NSLog(@"%@",locationResults);
Run Code Online (Sandbox Code Playgroud)
哪个是吐出一些结果,第一个是我想要的结果,但我不能像其他API一样得到lat和lng说:
NSString *stringLatitude = [locationResults objectForKey:@"lat"];
Run Code Online (Sandbox Code Playgroud)
我怀疑它正在寻找的关键是"结果"键的一个子集,我不知道如何告诉它:-(
结果:
2013-04-12 18:47:49.784 Test[26984:c07] {
"html_attributions" = (
);
results = (
{
"formatted_address" = "Sydney NSW, Australia";
geometry = {
location = {
lat = "-33.8674869";
lng = "151.2069902";
};
viewport = {
northeast = {
lat = "-33.4245981";
lng = "151.3426361";
};
southwest = {
lat = "-34.1692489";
lng = "150.502229";
};
};
};
Run Code Online (Sandbox Code Playgroud)
感谢任何指导!
您可以使用以下代码访问几何lat和lang
NSString *stringLatitude = [[[[[locationResults objectForKey:@"results"] objectAtIndex:0] objectForKey:@"geometry"] objectForKey:@"location"] valueForKey:@"lat"];
NSString *stringLongitude = [[[[[locationResults objectForKey:@"results"] objectAtIndex:0] objectForKey:@"geometry"] objectForKey:@"location"] valueForKey:@"lng"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2585 次 |
| 最近记录: |