0
ダウンロードしたJSONコンテンツに予想されるコンテンツではなくエラーメッセージが含まれているかどうかを確認するにはどうすればよいですか?私はURLを検証しようとしましたが、偽のサブドメイン(この場合は場所)がJSONコンテンツを通じてエラーメッセージを返す仕組みのため動作できません。もし誰かが私を助けることができたら、私はそれを感謝します。 (注:私は、ユーザーが入力した無効な場所をチェックしたいと私はAPIをOpenWeatherMap使用しています。)Swift - JSONファイルのエラーをチェックする方法
func downloadData(completed: @escaping()->()) {
print(url)
//UIApplication.shared.openURL(url as URL)
Alamofire.request(url).responseJSON(completionHandler: {
response in
let result = response.result
if let dict = result.value as? JSONStandard, let main = dict["main"] as? JSONStandard, let temp = main["temp"] as? Double, let weatherArray = dict["weather"] as? [JSONStandard], let weather = weatherArray[0]["main"] as? String, let name = dict["name"] as? String, let sys = dict["sys"] as? JSONStandard, let country = sys["country"] as? String, let dt = dict["dt"] as? Double {
self._temp = String(format: "%.0f °F", (1.8*(temp-273))+32)
self._weather = weather
self._location = "\(name), \(country)"
self._date = dt
}
completed()
})
}