Openweather API

时间:2017-10-09 06:22:37

标签: ios objective-c xcode openweathermap

我是第一次使用开放天气api制作应用程序,如何使用追加功能在网址中获取城市名称。 [在此输入链接描述] [1]

[super viewDidLoad];
NSError *error;
NSURLResponse *response;
NSString *urlString = [NSString stringWithFormat:@"http://api.openweathermap.org/data/2.5/weather?q=Westervile,oh,us&APPID=2fa22bb3ea6b43ae727b045b5e49e5f3"];

NSData*data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] returningResponse:&response error:&error];
NSString *citiesNamesResponse = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
totalCities=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];

NSDictionary *results = [citiesNamesResponse  JSONValue] ;
NSMutableString *mu = [NSMutableString stringWithString:urlString];
[mu insertString:@"name" atIndex:[mu length] - 39];

我正在设置名称(这是城市名称)以进入搜索栏。

0 个答案:

没有答案