arduino-libraries/Arduino_JSON

how to parse [] empty JSON elements

Closed this issue · 2 comments

I'm struggeling parsing a JASON-object received by OpenWeatherMap like this one:

{"coord":{"lon":9.18,"lat":47.66},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"stations","main":{"temp":284.22,"feels_like":282.44,"temp_min":283.15,"temp_max":284.82,"pressure":1013,"humidity":93},"visibility":10000,"wind":{"speed":2.6,"deg":50},"clouds":{"all":91},"dt":1591596373,"sys":{"type":1,"id":1310,"country":"DE","sunrise":1591586764,"sunset":1591643939},"timezone":7200,"id":2885679,"name":"Konstanz","cod":200}

Access induvidual values I use code like this:

float fTemp = obj["main"]["temp"].as<float>() -273.15;    with success

However the weather element:

"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],

is encapsulated in additional [...]
How can I access values for "id", "main", etc? in arduino/c++ idiom?

Trying:

  int id = obj["weather"]["0"]["id"].as<int>();                           
  String situation = obj["weather"]["0"]["main"].as<String>();  
  ...

compiles fine but give "0" or "null" as result

Thanl you for any advice

i got the same error and can't see reply of Benoit, how can you solve this