JSON library help

I am trying to parse this string from WeatherBit.io and I can't get the values from the Deserialization. My other weather JSON strings from another service work, it's just the string from Weatherbit.io that I can't figure out.

DeserializationError error = deserializeJson(doc, line);

tempM = doc["data"]["app_temp"];
wind_speed = doc["data"]["wind_spd"];
wind_dir = convert_windir((doc["data"]["wind_dir"]));
humiM = doc["data"]["rh"];
weatherCode = doc["data"]["weather"]["code"];

{"count":1,"data":[{"app_temp":78.1,"aqi":56,"city_name":"Huntington Farms","clouds":12,"country_code":"US","datetime":"2024-04-29:22","dewpt":60.5,"dhi":83.9,"dni":714.51,"elev_angle":24.27,"ghi":371.1,"gust":11.6,"h_angle":64.3,"lat":33.02,"lon":-80.21,"ob_time":"2024-04-29 22:25","pod":"d","precip":0,"pres":1014,"rh":55,"slp":1016.6716,"snow":0,"solar_rad":370.9,"sources":["rtma","radar","satellite"],"state_code":"SC","station":"G3674","sunrise":"10:33","sunset":"00:02","temp":78,"timezone":"America/New_York","ts":1714429502,"uv":2.3754683,"vis":9.3,"weather":{"description":"Few clouds","code":801,"icon":"c02d"},"wind_cdir":"S","wind_cdir_full":"south","wind_dir":170,"wind_spd":9.4}]}

It should be doc["data"][0]["app_temp"], same for other fields.

That works! I'm confused though, I ran the JSON string through Arduino Json Assistant it does not show the zero. Neither does Chrome when you select Pretty Print.

It's because elements enclosed between square brakets ([ ... ]) indicates an array (collection of elements).
So you have to specify which element in that collection you want to address by specifying its index number.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.