码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发——数据解析Swift篇&简单json数据处理

时间:2015-06-19 21:26:59      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

 

简单json数据处理

 

 1 //loadWeather
 2 
 3 var url = NSURL(string: "http://www.weather.com.cn/adat/sk/101240701.html")
 4 //提示没有这个方法?????????
 5 //var data = NSData.dataWithContentsOfURL(url!, options:NSDataReadingOptions.DataReadingUncached, error: nil)
 6 var data = NSData(contentsOfURL: url!, options: NSDataReadingOptions.DataReadingUncached, error: nil)
 7 
 8 
 9 var json: AnyObject? = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments, error: nil)
10 /**
11 var weatherInfo.....
12     (.0 "cityid", .1 "101010100")
13 (.0 "city", .1 "北京")
14 (.0 "time", .1 "19:05")
15 (.0 "isRadar", .1 "1")
16 */
17 /**
18 {"weatherinfo":{"city":"赣州","cityid":"101240701","temp":"26","WD":"西南风","WS":"4级","SD":"63%","WSE":"4","time":"10:30","isRadar":"1","Radar":"JC_RADAR_AZ9797_JB","njd":"暂无实况","qy":"992"}}
19 */
20 //解析
21 var weatherInfo: AnyObject? = json?.objectForKey("weatherinfo: AnyObject?")
22 
23 var city: AnyObject? = weatherInfo?.objectForKey("city")
24 
25 var temo: AnyObject? = weatherInfo?.objectForKey("temp")
26 
27 var wind: AnyObject? = weatherInfo?.objectForKey("WD")

 

 

iOS开发——数据解析Swift篇&简单json数据处理

标签:

原文地址:http://www.cnblogs.com/iCocos/p/4589639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!