IOS-天气API
来源:互联网 发布:高考大数据 编辑:程序博客网 时间:2024/06/11 23:58
这里只是一个简单的获取天气信息的Demo。
//// ViewController.m// 1-天气查询API//// Created by Jarvan on 15/5/21.// Copyright (c) 2015年 Jarvan. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (nonatomic, strong) UIButton *button;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.button];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
// 在storyboard中拖一个按键,以下点击按键的方法- (IBAction)buttonClick:(UIButton *)sender { NSString *urlstr = @"http://m.weather.com.cn/data/101010100.html"; NSURL *url = [NSURL URLWithString:urlstr]; // 创建一个请求 NSURLRequest *request = [NSURLRequest requestWithURL:url]; // 发送一个同步请求 NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; // 解析JSON数据 // {"weatherinfo":{"city":"北京","city_en":"beijing","date_y":"2014年3月4日","date":"","week":"星期二","fchh":"11","cityid":"101010100","temp1":"8℃~-3℃","temp2":"8℃~-3℃","temp3":"7℃~-3℃","temp4":"8℃~-1℃","temp5":"10℃~1℃","temp6":"10℃~2℃","tempF1":"46.4℉~26.6℉","tempF2":"46.4℉~26.6℉","tempF3":"44.6℉~26.6℉","tempF4":"46.4℉~30.2℉","tempF5":"50℉~33.8℉","tempF6":"50℉~35.6℉","weather1":"晴","weather2":"晴","weather3":"晴","weather4":"晴转多云","weather5":"多云","weather6":"多云","img1":"0","img2":"99","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"1","img10":"99","img11":"1","img12":"99","img_single":"0","img_title1":"晴","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"晴","img_title6":"晴","img_title7":"晴","img_title8":"多云","img_title9":"多云","img_title10":"多云","img_title11":"多云","img_title12":"多云","img_title_single":"晴","wind1":"北风4-5级转微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风","fx1":"北风","fx2":"微风","fl1":"4-5级转小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级","index":"寒冷","index_d":"天气寒冷,建议着厚羽绒服、毛皮大衣加厚毛衣等隆冬服装。年老体弱者尤其要注意保暖防冻。","index48":"冷","index48_d":"天气冷,建议着棉服、羽绒服、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣、冬大衣或厚羽绒服。","index_uv":"中等","index48_uv":"中等","index_xc":"较适宜","index_tr":"一般","index_co":"较舒适","st1":"7","st2":"-3","st3":"8","st4":"0","st5":"7","st6":"-1","index_cl":"较不宜","index_ls":"基本适宜","index_ag":"易发"}} NSDictionary *dirt =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSDictionary *dirt2 = dirt[@"weatherinfo"]; NSString *city = dirt2[@"city"]; NSString *city_e = dirt2[@"city_en"]; NSString *date_y = dirt2[@"date_y"]; NSString *temp1 = dirt2[@"temp1"]; NSString *temp2 = dirt2[@"temp1"]; NSString *temp3 = dirt2[@"temp1"]; NSLog(@"你所在的城市:%@ %@;\n日期:%@;\n天气情况:\n今天:%@;\n明天:%@;\n后天:%@;\n",city,city_e,date_y,temp1,temp2,temp3);
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(0, 143, 0);">// <span style="font-family: 'Heiti SC Light';">你所在的城市</span>:<span style="font-family: 'Heiti SC Light';">北京</span> beijing;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(0, 143, 0);">// <span style="font-family: 'Heiti SC Light';">日期</span>:2014<span style="font-family: 'Heiti SC Light';">年</span>3<span style="font-family: 'Heiti SC Light';">月</span>4<span style="font-family: 'Heiti SC Light';">日</span>;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(0, 143, 0);">// <span style="font-family: 'Heiti SC Light';">天气情况</span>:</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(0, 143, 0);">// <span style="font-family: 'Heiti SC Light';">今天</span>:8<span style="font-family: Monaco;">℃</span>~-3<span style="font-family: Monaco;">℃</span>;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(0, 143, 0);">// <span style="font-family: 'Heiti SC Light';">明天</span>:8<span style="font-family: Monaco;">℃</span>~-3<span style="font-family: Monaco;">℃</span>;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; font-family: Menlo; color: rgb(0, 143, 0);">// <span style="font-family: 'Heiti SC Light';">后天</span>:8<span style="font-family: Monaco;">℃</span>~-3<span style="font-family: Monaco;">℃</span>;</p>@end
0 0
- IOS-天气API
- 天气Api
- 天气API
- 天气 API
- 天气api
- 天气API
- 天气API
- 天气api
- 【iOS开发】如何使用中国气象局API开发天气APP
- iOS 简单调用全国天气API,解析JSON
- 百度天气API 获取天气
- google 天气免费api
- 天气接口API
- 各种天气API
- 各种天气API
- 新浪天气API接口
- 各种天气API
- 中央气象台天气api分析
- 连载一 新的开始
- oracle 常用查询总结
- [150521]讲述Linux ftp命令的使用方法
- Android将日志信息自动发送到指定的邮箱中 邮件的内容以附件形式发送
- Android AlarmManager实现不间断轮询服务
- IOS-天气API
- glUnmapBuffer
- mybatis--增删查改的基本mapper的xml配置
- linux awk 命令
- 判断俩个链表是否相交
- 《C#游戏开发快速入门教程》
- strongswan5.1.2 on ubuntu14.04 (net-net with psk)
- 绘制图形
- Bit Manipulation Reverse Bits