-1
是否有可能從我國的一些銀行網站獲取貨幣匯率,這是合法的嗎?Json從銀行賬戶分析快速3貨幣兌換值
製作一個應用程序指定給我的國家,並已嘗試了一個星期,但無法找到答案這是您可以告訴解決方案的代碼?
import UIKit
class ViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
@IBOutlet weak var lblDisplay: UILabel!
@IBOutlet weak var txtField: UITextField!
@IBOutlet weak var pkrView: UIPickerView!
var myCurrency:[String] = []
var myValue:[Double] = []
var activeCurrency:Double = 0
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "http://ca-egypt.com")
let task = URLSession.shared.dataTask(with: url!) { (data, response, error)in
if error != nil{
print("error is here!")
}else{
if let content = data{
do{
let myJson = try JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers) as AnyObject
if let rates = myJson["rates"] as? NSDictionary{
var firstOne = true
for (key,value)in rates{
self.myCurrency.append((key as? String)!)
self.myValue.append((value as? Double)!)
}
}
}catch{
}
}
}
self.pkrView.reloadAllComponents()
}
task.resume()
}
@IBAction func btnCalculateAction(_ sender: UIButton) {
lblDisplay.text = String(Double(txtField.text!)! * activeCurrency)
}
func numberOfComponents(in pickerView: UIPickerView,umberOfRowsInComponent component: Int) -> Int {
return myCurrency.count
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return myCurrency.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return myCurrency[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
activeCurrency = myValue[row]
}
}
錯誤的圖片:
請將錯誤消息添加爲純文本。所以它可以被索引並且可以從巫婆行搜索 – muescha
它開始? – muescha
抓取通常不合法 – muescha