IOS开发之----天气接口的调用

1.下边方法zipCode参数是天气网站里面的一个城市编码,根据zipCode查询


北京的编码是:101010100


+(NSString*)getWeatherXmlForZipCode:(NSString*)zipCode {

NSError *error;

NSURLResponse *response;

NSData *dataReply;

NSString *stringReply;

NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL: [NSURL URLWithString:[NSString stringWithFormat:@"http://m.weather.com.cn/data/%@.html",zipCode]]];

[request setHTTPMethod:@"GET"];

dataReply = [NSURLConnectionsendSynchronousRequest:requestreturningResponse:&responseerror:&error];

stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];

NSLog(stringReply);

return stringReply;

}


2.返回的字符串展示在UIWebView


 

NSString* weatherXml = [AmuckWeathergetWeatherXmlForZipCode:textField.text];

NSData* htmlData = [weatherXmldataUsingEncoding:NSUTF8StringEncoding];

[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:nil];


有关天气接口信息网站如下

http://wishblog.sinaapp.com/378

你可能感兴趣的:(IOS类库)