标签:
简单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")
标签:
原文地址:http://www.cnblogs.com/iCocos/p/4589639.html