在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
暑假在家闲着没事干,心血来潮想做个天气预报APP玩玩,听说和风天气API很好,于是注册并试了下,结果它的JSON是这样的(拿我的家乡武义为例子) {"HeWeather data service 3.0":[{"aqi":{"city":{"aqi":"73","pm10":"54","pm25":"39","qlty":"良"}},"basic":{"city":"武义","cnty":"中国","id":"CN101210906","lat":"28.530000","lon":"119.480000","update":{"loc":"2016-08-16 17:52","utc":"2016-08-16 09:52"}},"daily_forecast":[{"astro":{"sr":"05:32","ss":"18:40"},"cond":{"code_d":"100","code_n":"101","txt_d":"晴","txt_n":"多云"},"date":"2016-08-16","hum":"54","pcpn":"0.0","pop":"0","pres":"1001","tmp":{"max":"38","min":"27"},"vis":"10","wind":{"deg":"121","dir":"无持续风向","sc":"微风","spd":"3"}},{"astro":{"sr":"05:32","ss":"18:39"},"cond":{"code_d":"100","code_n":"100","txt_d":"晴","txt_n":"晴"},"date":"2016-08-17","hum":"54","pcpn":"0.0","pop":"1","pres":"1000","tmp":{"max":"38","min":"27"},"vis":"10","wind":{"deg":"123","dir":"东风","sc":"微风","spd":"10"}},{"astro":{"sr":"05:33","ss":"18:38"},"cond":{"code_d":"100","code_n":"100","txt_d":"晴","txt_n":"晴"},"date":"2016-08-18","hum":"55","pcpn":"0.0","pop":"1","pres":"1000","tmp":{"max":"38","min":"28"},"vis":"10","wind":{"deg":"148","dir":"东风","sc":"微风","spd":"3"}},{"astro":{"sr":"05:33","ss":"18:37"},"cond":{"code_d":"101","code_n":"101","txt_d":"多云","txt_n":"多云"},"date":"2016-08-19","hum":"56","pcpn":"0.0","pop":"0","pres":"1000","tmp":{"max":"38","min":"29"},"vis":"10","wind":{"deg":"158","dir":"东风","sc":"微风","spd":"8"}},{"astro":{"sr":"05:34","ss":"18:36"},"cond":{"code_d":"101","code_n":"101","txt_d":"多云","txt_n":"多云"},"date":"2016-08-20","hum":"49","pcpn":"0.0","pop":"8","pres":"1001","tmp":{"max":"37","min":"27"},"vis":"10","wind":{"deg":"138","dir":"东风","sc":"微风","spd":"0"}},{"astro":{"sr":"05:34","ss":"18:35"},"cond":{"code_d":"101","code_n":"101","txt_d":"多云","txt_n":"多云"},"date":"2016-08-21","hum":"46","pcpn":"0.0","pop":"0","pres":"1002","tmp":{"max":"36","min":"26"},"vis":"10","wind":{"deg":"100","dir":"东风","sc":"微风","spd":"4"}},{"astro":{"sr":"05:35","ss":"18:34"},"cond":{"code_d":"101","code_n":"101","txt_d":"多云","txt_n":"多云"},"date":"2016-08-22","hum":"45","pcpn":"0.0","pop":"0","pres":"1003","tmp":{"max":"35","min":"25"},"vis":"10","wind":{"deg":"89","dir":"东风","sc":"微风","spd":"0"}}],"hourly_forecast":[{"date":"2016-08-16 19:00","hum":"72","pop":"0","pres":"1001","tmp":"36","wind":{"deg":"136","dir":"东南风","sc":"微风","spd":"7"}},{"date":"2016-08-16 22:00","hum":"83","pop":"0","pres":"1003","tmp":"34","wind":{"deg":"142","dir":"东南风","sc":"微风","spd":"8"}}],"now":{"cond":{"code":"100","txt":"晴"},"fl":"44","hum":"43","pcpn":"0","pres":"1000","tmp":"36","vis":"10","wind":{"deg":"128","dir":"东风","sc":"4-5","spd":"20"}},"status":"ok","suggestion":{"comf":{"brf":"极不舒适","txt":"白天天气晴好、炎热,您会感到酷热难耐,极为不适,请注意防暑降温。"},"cw":{"brf":"较适宜","txt":"较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。"},"drsg":{"brf":"炎热","txt":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫等清凉夏季服装。"},"flu":{"brf":"少发","txt":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。"},"sport":{"brf":"较适宜","txt":"天气较好,户外运动请注意防晒。推荐您进行室内运动。"},"trav":{"brf":"较不宜","txt":"天气较好,温度比较高,中午时段尽量不要外出,如外出可选择水上娱乐等清凉项目。并请注意防暑和防晒。"},"uv":{"brf":"强","txt":"紫外线辐射强,建议涂擦SPF20左右、PA++的防晒护肤品。避免在10点至14点暴露于日光下。"}}}]} 你赢了,我选择死亡 由于奇葩的格式连json解析工具也不能用,好吧我就不厌其烦地层层解析.... 注意:{}代表NSDictionary,[]和()代表NSArray。也算是学到了一点
-(void)requestForApi:(NSDictionary*)jsonDict{//接收json中的api内容 NSDictionary *wyCity = [[jsonDict objectForKey:@"aqi"] objectForKey:@"city"]; NSString *wyAqiStr = [wyCity objectForKey:@"aqi"]; NSString *wyPm10 = [wyCity objectForKey:@"pm10"]; NSString *wyPm25 = [wyCity objectForKey:@"pm25"]; NSString *wyQlty = [wyCity objectForKey:@"qlty"]; } -(void)requestForBasic:(NSDictionary*)jsonDict{ NSDictionary *wyBasic = [jsonDict objectForKey:@"basic"]; NSString *wyCity = [wyBasic objectForKey:@"city"]; NSString *wyCnty = [wyBasic objectForKey:@"cnty"]; NSString *wyId = [wyBasic objectForKey:@"id"]; NSString *wyLat = [wyBasic objectForKey:@"lat" |
请发表评论