import Foundation import CryptoSwift struct JsonSample : Codable { var high : Double var open : Double var bid : Double var currencyPairCode : String var ask : Double var low: Double } let listUrl = "https://www.gaitameonline.com/rateaj/getrate" let url = URL(string: listUrl) URLSession.shared.dataTask(with: url) { (data, response, error) in if error != nil { print(error!.localizedDescription) } guard let data = data else { return } let json = try? JSONDecoder().decode([JsonSample].self, from: data) }.resume() print(json.bid)
エラーになる。何故だ。。。
/tmp/EA9CF30B-2A75-422F-B05F-493561545E26.sMmRoI/main.swift:19:34: error: value of optional type ‘URL?’ not unwrapped; did you mean to use ‘!’ or ‘?’?
URLSession.shared.dataTask(with: url) { (data, response, error) in
^
!
/tmp/EA9CF30B-2A75-422F-B05F-493561545E26.sMmRoI/main.swift:29:7: error: use of unresolved identifier ‘json’
print(json.bid)
なんかうまくいかない。
let url:URL = URL(string: "")! let task = URLSession.shared.dataTask(with: url){ data, response, error in if let error = error{ print(error.localizedDescription) return } if let response = response as? HTTPURLResponse { print("response.statusCode = \(response.statusCode)") } } task.resume()