0
私は迅速かつプログラミングの面で新しく、JSONファイルがシンプルであればAlamofireとSwiftyJSONの助けを借りてJSONを解析しようとしています。私は辞書のようなものを持っている - >辞書 - >アレイ - >辞書、問題が始まるので、私は次のコードを持っている:Alamofireの問題でJSONを解析する
func performCYesterdayWeatherFetch(forSelectedCity: String)
{
let properString = forSelectedCity.addingPercentEncoding(withAllowedCharacters:NSCharacterSet.urlQueryAllowed)
Alamofire.request("http://api.apixu.com/v1/history.json?key=MY_KEY&q=\(properString!)&dt=2016-10-20").responseJSON { (response) -> Void in
guard response.result.isSuccess else
{
print("Error while fetching remote rooms: \(response.result.error)")
return
}
guard let json = response.result.value as? JSON,
let forecastJson = json["forecast"].dictionary else
{
print("YESTERDAY PROBLEM")
return
}
for item in (forecastJson["forecastday"]?.arrayValue)!
{
let day = item["day"].dictionaryObject
guard let yesterdayTempCels = day?["avgtemp_c"] as! Double?,
let yesterdayTempFahr = day?["avgtemp_f"] as! Double? else
{
return
}
MY_KEYを - 実際に私の鍵であり、問題はそれではない私は入力しませんでしたキー。
それは、常に他のここでの取得:
guard let json = response.result.value as? JSON,
let forecastJson = json["forecast"].dictionary else
{
print("YESTERDAY PROBLEM")
return
}
彼らはJSONはそのように見える結果: 私は必要薄いが私が間違っているのは何avgtemp_cあると
avgtemp_f?
「JSON」型はどこにありますか? – EridB
私はチュートリアルでそれを見ましたが、要求から私はJSONファイルを取得しました。他の例では(1つの配列はどこにありますか)... –
JSONとしてライブラリ(おそらく 'SwiftyJSON'を使用しています) 'Alamofire'の中のタイプではありません。' iOS API's 'でもありません。 – EridB