简单天气应用开发——解析HeWeather JSON
借助和风天气API成功获取到了我想要的天气信息,但在怎么提取出我想要的数据上又遇到了问题。
{"HeWeather data service 3.0":[{"basic":{"city":"余姚","cnty":"中国","id":"CN101210404","lat":"29.948000","lon":"121.172000","update":{"loc":"2016-02-06 14:58","utc":"2016-02-06 06:58"}},"daily_forecast":[{"astro":{"sr":"06:42","ss":"17:36"},"cond":{"code_d":"101","code_n":"100","txt_d":"多云","txt_n":"晴"},"date":"2016-02-06","hum":"44","pcpn":"0.0","pop":"2","pres":"1030","tmp":{"max":"6","min":"-2"},"vis":"10","wind":{"deg":"324","dir":"西北风","sc":"3-4","spd":"12"}},{"astro":{"sr":"06:41","ss":"17:36"},"cond":{"code_d":"100","code_n":"100","txt_d":"晴","txt_n":"晴"},"date":"2016-02-07","hum":"31","pcpn":"0.0","pop":"0","pres":"1024","tmp":{"max":"9","min":"-2"},"vis":"10","wind":{"deg":"282","dir":"西北风","sc":"3-4","spd":"12"}},{"astro":{"sr":"06:41","ss":"17:37"},"cond":{"code_d":"100","code_n":"100","txt_d":"晴","txt_n":"晴"},"date":"2016-02-08","hum":"32","pcpn":"0.0","pop":"0","pres":"1024","tmp":{"max":"14","min":"1"},"vis":"10","wind":{"deg":"274","dir":"西风","sc":"微风","spd":"6"}},{"astro":{"sr":"06:40","ss":"17:38"},"cond":{"code_d":"100","code_n":"100","txt_d":"晴","txt_n":"晴"},"date":"2016-02-09","hum":"30","pcpn":"0.0","pop":"0","pres":"1023","tmp":{"max":"16","min":"6"},"vis":"10","wind":{"deg":"95","dir":"南风","sc":"3-4","spd":"12"}},{"astro":{"sr":"06:39","ss":"17:39"},"cond":{"code_d":"101","code_n":"101","txt_d":"多云","txt_n":"多云"},"date":"2016-02-10","hum":"51","pcpn":"0.0","pop":"0","pres":"1020","tmp":{"max":"18","min":"8"},"vis":"10","wind":{"deg":"167","dir":"东南风","sc":"3-4","spd":"10"}},{"astro":{"sr":"06:38","ss":"17:40"},"cond":{"code_d":"300","code_n":"101","txt_d":"阵雨","txt_n":"多云"},"date":"2016-02-11","hum":"60","pcpn":"0.3","pop":"51","pres":"1015","tmp":{"max":"19","min":"10"},"vis":"10","wind":{"deg":"177","dir":"南风","sc":"微风","spd":"9"}},{"astro":{"sr":"06:38","ss":"17:40"},"cond":{"code_d":"101","code_n":"101","txt_d":"多云","txt_n":"多云"},"date":"2016-02-12","hum":"54","pcpn":"7.0","pop":"50","pres":"1010","tmp":{"max":"20","min":"11"},"vis":"10","wind":{"deg":"241","dir":"南风","sc":"3-4","spd":"11"}}],"hourly_forecast":[{"date":"2016-02-06 16:00","hum":"46","pop":"1","pres":"1030","tmp":"5","wind":{"deg":"326","dir":"西北风","sc":"3-4","spd":"26"}},{"date":"2016-02-06 19:00","hum":"50","pop":"0","pres":"1031","tmp":"3","wind":{"deg":"325","dir":"西北风","sc":"3-4","spd":"19"}},{"date":"2016-02-06 22:00","hum":"55","pop":"0","pres":"1031","tmp":"2","wind":{"deg":"308","dir":"西北风","sc":"微风","spd":"14"}}],"now":{"cond":{"code":"101","txt":"多云"},"fl":"3","hum":"54","pcpn":"0","pres":"1029","tmp":"3","vis":"6","wind":{"deg":"330","dir":"西风","sc":"5-6","spd":"30"}},"status":"ok","suggestion":{"comf":{"brf":"较不舒适","txt":"白天天气晴好,但仍会使您感觉偏冷,不很舒适,请注意适时添加衣物,以防感冒。"},"cw":{"brf":"较适宜","txt":"较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。"},"drsg":{"brf":"冷","txt":"天气冷,建议着棉服、羽绒服、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣、冬大衣或厚羽绒服。"},"flu":{"brf":"易发","txt":"昼夜温差很大,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。"},"sport":{"brf":"较不宜","txt":"天气较好,但考虑天气寒冷,风力较强,推荐您进行室内运动,若户外运动请注意保暖并做好准备活动。"},"trav":{"brf":"一般","txt":"天空状况还是比较好的,但温度稍微有点低,且风稍大,会让您感觉些许凉意。外出请注意防风。"},"uv":{"brf":"最弱","txt":"属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。"}}}]}
这串JSON和我以前学习JSON解析时的完全不一样,字典和数组一层套一层,看得头都晕了。还好有JSON在线视图查看器,导入后可以清晰的看到层次结构:
现在就好办多了,只要一层层地把数据剥出来就OK
NSArray *preData = dict[ @"HeWeather data service 3.0" ];];NSDictionary *basic = weatherData[@"basic" ];NSArray *dailyForecast = weatherData[@"daily_forecast" ];NSDictionary *now = weatherData[@"now" ];
简单天气应用开发——解析HeWeather JSON的更多相关文章
- IOS开发--解析复杂json数据
json的自我介绍:JSON(JavaScript Object Notation)是一种轻量级的数据交换格式.JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言.易于人阅 ...
- 简单天气应用开发——API接口
寒假回家无事,想到自学iOS开发已有一段时间,还没做过真正自己的应用,就起了做一个天气预报App的念头. 想到就做.天气预报第一步自然是找到好用的API接口来获取天气信息.在百度上搜索了一圈,找到的都 ...
- 简单天气应用开发——自定义TableView
顺利解析JSON数据后,天气数据已经可以随意提取了,现在要做的就是建立一个简单的UI. 实况信息较为简单,几个Lable就可以解决.主要是七天天气预报有点麻烦,那是一个由七个字典构成的数组,需要提取出 ...
- iOS开发网络篇—JSON数据的解析
iOS开发网络篇—JSON数据的解析 iOS开发网络篇—JSON介绍 一.什么是JSON JSON是一种轻量级的数据格式,一般用于数据交互 服务器返回给客户端的数据,一般都是JSON格式或者XML格式 ...
- 简单快速的让你的json解析速度快上加快
背景 最近小编在做公司的一个需求.要求是把系统内的一些大型文本文件上传到第三方那里,而且第三方要求的交互数据的方式是采用post请求发送json串的形式进行的. 问题 做到中途才发现问题,由于单个文本 ...
- 5分钟让你学会用最高效的工具解析所有Json
如果你是一个Android开发工程师,学会解析Json字符串是你的必修课,本篇文章主要以实例的方式手把手教你怎么做,花五分钟时间阅读本篇文章你就可以学会解析所有的Json字符串啦. 准备: json字 ...
- 基于Django进行简单的微信开发
代码地址如下:http://www.demodashi.com/demo/11756.html 一.微信公众号的准备: 1. 注册 访问地址:https://mp.weixin.qq.com/ 按照提 ...
- 最强常用开发库总结 - JSON库详解
最强常用开发库总结 - JSON库详解 JSON应用非常广泛,对于Java常用的JSON库要完全掌握.@pdai JSON简介 JSON是什么 JSON 指的是 JavaScript 对象表示法(Ja ...
- fastjson解析任意json
fastjson解析任意json到bean 解析案例的代码 package com.base.config; import java.util.List; import com.alibaba.fas ...
随机推荐
- ReentrantLock(重入锁)以及公平性
ReentrantLock(重入锁)以及公平性 标签(空格分隔): java NIO 如果在绝对时间上,先对锁进行获取的请求一定被先满足,那么这个锁是公平的,反之,是不公平的,也就是说等待时间最长的线 ...
- RMA编码为必输
应用 Oracle Inventory 层 Level Function 函数名 Funcgtion Name RCV_RCVTXERE 表单名 Form Name RCVTXERE 说明 Descr ...
- bash代码
bash代码: #!/bin/bash MySQLSTARTUP="/data/3306/mysql" DbProcessCount=`ps -ef|grep mysql|grep ...
- iOS获取手机当前的网络状态
获取iOS网络状态,目前有两个办法. 1.通过监听手机状态栏的信息. 2.通过使用官方提供的类Reachability. 一.通过手机监听手机状态栏的信息 好处: 1.可以通过苹果的审核上架AppSt ...
- Div实现滚动条效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 腾讯TGideas语义化标签(转)
--------引子--------------- 家里有个熊孩子,经常会有一些意想不到的事情发生:回家的时候,他会笑呵呵冲过来,大声喊着“臭爸爸”:你让他把鞋穿上,他会提起鞋子往楼下扔...在小孩的 ...
- jQuery的三种$()
参考脚本之家“http://www.jb51.net/article/21660.htm” $号是jQuery“类”的一个别称,$()构造了一个jQuery对象.所以,“$()”可以叫做jQuer ...
- Csharp多态的实现(虚方法)
1.什么是抽象类 1.1虚方法是用virtual修饰,在子类中用override进行重写 1.2虚方法是一个方法,放在类里面(可以再下面的代码中看到) 1.3虚方法可以 重写,也可以不重写(这个可以再 ...
- Problem G: If We Were a Child Again
Problem G: If We Were a Child AgainTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 14[Submi ...
- 兼容现有jQuery API的轻量级JavaScript库:Zepo
Zepo是一个JavaScript框架,其特点是兼容现有jQuery API的同时,自身体积十分小:它与jQuery有着类似的API.如果你会jQuery,那么也就会使用Zepto了. $('div' ...