任何人都可以告訴我如何解決這個問題嗎?我只是試圖從事情發言接收信號。條件綁定的初始值設定項必須有可選類型,而不是'[String:Any]'
`self.title = "Home"
print("Requesting data...")
Alamofire.request("https://api.thingspeak.com/channels/290427/feeds.json", parameters: ["results": "1", "location": "false"]) // Gets the latest info from ThingSpeak
.responseJSON { response in
print("Data downloaded: \(response.result)")
if let json = response.result.value as! [String:Any] {
print(json) //see full data
if let feeds = json["feeds"] as? [String: Any] {
for feed in feeds {
print(feed["field2"])
if let temperatureStr = feed["field2"] as? String, let dateStr = feed["created_at"] as? String {
if let temperature = Double(temperatureStr){
self.label.text = "Temperature: \(temperature)°F" //Displays last updated data entry
}
的錯誤是在該行
if let json = response.result.value as! [String:Any] {
錯誤消息稱「初始值設定條件結合必須有可選的類型,而不是‘[字符串:任何]’
更換'的'的'的!? '(如你在下面2行)。 - 順便說一句,你的問題標題甚至不符合錯誤消息。 –