Swift +AFNetworking3.0 Get
Posted Sinner_Yun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Swift +AFNetworking3.0 Get相关的知识,希望对你有一定的参考价值。
1 let manager = AFHTTPSessionManager()
2 let url = "http://v.juhe.cn/weather/index"
3 let params = ["format":2,"cityname":city,"key":"ead46e88f98d0cd48730bdcde2"]
4
5 //progress做任务进度获取
6 manager.GET(url, parameters: params, progress: nil, success: { (_, JSON) in
7 print(JSON)
8 var temperature: String
9 var weatherIcon: String
10 var weatherText: String
11
12 let dis = JSON as! NSDictionary
13
14
15 temperature = (dis["result"]?["today"]?!["temperature"]?! as? String)!
16 weatherText = (dis["result"]?["today"]?!["weather"]?! as? String)!
17 weatherIcon = (dis["result"]?["today"]?!["weather_id"]?!["fa"]?! as? String)!
18
19 self.temperature.text = temperature
20 self.Weather.text = weatherText
21 self.location.text = city
22
23
24 default:
25 print("Error==")
26 }
27
28
29
30 }, failure: { (_, error) in
31 print(error)
32
33 })
以上是关于Swift +AFNetworking3.0 Get的主要内容,如果未能解决你的问题,请参考以下文章