在k780.com上獲取數據:
1.生成二維碼:
let url = NSURL(string: "http://api.k780.com:88/?app=qr.get&data=testqqqq&level=L&size=6")!
let request = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue()) { (_, data, error) -> Void in
if error == nil {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.qrcodeImageView.image = UIImage(data: data)
})
}
}
let weatherRequest = NSURLRequest(URL: NSURL(string: "http://api.k780.com:88/? app=weather.future&weaid=1&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json)!)
NSURLConnection.sendAsynchronousRequest(weatherRequest, queue: NSOperationQueue()) { (_, data, error) - > Void in
if error == nil {
if let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as? NSDictionary {
if let result = json.valueForKey("result") as? NSArray {
if let resultToday = result[0] as? NSDictionary{
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.locationLable.text = resultToday["citynm"] as? String
self.weatherLable.text = resultToday["weather"] as? String
self.tempLable.text = resultToday["temperature"] as? String
})
}
}
}
}
}