-1

i have this from an API:

{"coord":{"lon":26.1,"lat":44.44},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":27.98,"pressure":1011,"humidity":30,"temp_min":27,"temp_max":29},"visibility":10000,"wind":{"speed":1.5,"deg":80},"clouds":{"all":0},"dt":1535128200,"sys":{"type":1,"id":5986,"message":0.0256,"country":"RO","sunrise":1535081370,"sunset":1535130317},"id":683506,"name":"Bucharest","cod":200}

how can I get the humidity? here is my function which doesn't work:

$.getJSON("https://api.openweathermap.org/data/2.5/weather?q=Slatina,ro&appid=b877cc138ceeb7015615b7b122be7958&units=metric", function(result){
document.getElementById("vremeaText").innerHTML = result.weather[0].humidity;
Prodan Mihai
  • 21
  • 1
  • 3
  • 3
    Try `result.main.humidity` – brk Aug 24 '18 at 17:26
  • `const obj = {"coord":{"lon":26.1,"lat":44.44},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":27.98,"pressure":1011,"humidity":30,"temp_min":27,"temp_max":29},"visibility":10000,"wind":{"speed":1.5,"deg":80},"clouds":{"all":0},"dt":1535128200,"sys":{"type":1,"id":5986,"message":0.0256,"country":"RO","sunrise":1535081370,"sunset":1535130317},"id":683506,"name":"Bucharest","cod":200} console.log(obj.main.humidity);` – A l w a y s S u n n y Aug 24 '18 at 17:27
  • I didn't know that API, it's amazing – Emeeus Aug 24 '18 at 17:33

1 Answers1

1

Use:

result.main.humidity;

Instead of:

result.weather[0].humidity;

I suggest you use JSON formatter to make it easier for you to see the actual of a JSON object.

AmmoPT
  • 958
  • 1
  • 9
  • 16