//
// ViewController.swift
// SeSSAC-WEEK5-CLASS
//
// Created by mac on 2021/10/25.
//
import UIKit
import Alamofire
import SwiftyJSON
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
getCurrentWeather()
}
func getCurrentWeather(){
let url = "https://api.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,10&appid=69f4c041bdfafce7925e677a1079844e"
AF.request(url, method: .get).validate().responseJSON { response in
switch response.result {
case .success(let value): //성공했을 때(let 연관값)
let json = JSON(value)
print("JSON: \(json)")
case .failure(let error): //실패했을 때
print(error)
}
}
}
}
데이터형식: JSON
String타입에 JSON
Swift로 연결될 수 있게 제이슨시리얼라이제이션 을 해야한다.
근데 요즘은 잘 안쓰는듯???
위에 사용한 라이브러리에서 자동으로 해주고있음
JSON: {
"cnt" : 15,
"calctime" : 0.0017665179999999999,
"list" : [
{
"name" : "Birkirkara",
"rain" : null,
"weather" : [
{
"id" : 801,
"description" : "few clouds",
"icon" : "02n",
"main" : "Clouds"
}
],
GCP/Opertation 에 이어서 포스팅