❔ Accessing json results for a weather api console app
https://paste.mod.gg/jtzzrouisnhf/0
I'm trying to access the temperatures, but when I try to get back a list according to how i have it in the WeatherInfo.cs class, it doesn't work. Any suggestions?
BlazeBin - jtzzrouisnhf
A tool for sharing your source code with the world!
10 Replies
mapping is wrong, you send 3 get requests to 1 url and map it into different objects. solution would be to map it into one object
{"latitude":33.98601,"longitude":-117.748215,"generationtime_ms":0.3509521484375,"utc_offset_seconds":-25200,"timezone":"America/Los_Angeles","timezone_abbreviation":"PDT","elevation":295.0,"daily_units":{"time":"iso8601","temperature_2m_max":"°F"},"daily":{"time":["2023-06-17","2023-06-18","2023-06-19","2023-06-20","2023-06-21","2023-06-22","2023-06-23"],"temperature_2m_max":[86.3,79.6,76.9,80.0,81.4,77.6,78.2]}}
should be something like that
so to map into one object, would it be a single get request into an object of the WeatherInfo class?
and i decided not to include some of those properties because i was told i could ignore them if i didn't want them
in this case i only want what i ahve in my current class, but when i call the api it gives me stuff i dont want
you can exclude some properties of you dont want them
oh i think i see it now, so i want to call dailyunits and daily in the weather class
and that would be just one object that i could call everything from
i'm confused on how i would access each daily and dailyunits entry though
from this my output is
rootResults.daily.time[0]
wow
that was exactly what i needed
thank you
no problem
$close
Use the
/close
command to mark a forum thread as answeredWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.