r9young / DECO7140-Final-Project

0 stars 0 forks source link

How to Read Json file #14

Open r9young opened 3 months ago

r9young commented 3 months ago

{
"latitude": -27.5,
"longitude": 153,
"generationtime_ms": 0.0209808349609375,
"utc_offset_seconds": 0,
"timezone": "GMT",
"timezone_abbreviation": "GMT",
"elevation": 27,
["current_units"](https://api.open-meteo.com/v1/forecast?latitude=-27.4679&longitude=153.0281&current=temperature_2m,rain,cloud_cover): {
"time": "iso8601",
"interval": "seconds",
"temperature_2m": "°C",
"rain": "mm",
"cloud_cover": "%"
},
["current"](https://api.open-meteo.com/v1/forecast?latitude=-27.4679&longitude=153.0281&current=temperature_2m,rain,cloud_cover): {
"time": "2024-05-15T03:15",
"interval": 900,
"temperature_2m": 24.2,
"rain": 0,
"cloud_cover": 93
}
}

current_unit & current are Keys that contain the current weather data object.


fetch(urlWithParams, requestOptions)
    .then(response => response.json()) // Convert the response to JSON
    .then(data => {
        // Extract the current weather data from the response
        const weather = data.current;
        console.log(weather); 

Therefore this is why we use const weather = data.current; rather than const weather = data.current_temp