Weather API not working

Weather API not working
0.0 0

#1

Hello Campers,
I’m trying to use the Free Code weather API and Although the request is successful I can’ t extract the information from the returned object json , it gives me only undefined … I wounder why
here is my codepen : https://codepen.io/HamedOKhaled/pen/gzxqmX
Thanks :slight_smile:


#2
 $.getJSON(url,function(json){
      console.log(json);
  });

try not to grab specific data when you fetch. you’ll have other functions to handle that


#3

I tried this and I checked the console it says that the josn is array(12) and gives each property an index so I tried to print it as array of object… same error!


#4

what are trying to do exactly?


#5

I try to extract information from the returned JSON object ,
so for example how i can know the whether if it’s sunny or rainy ?


#6

arrays start at zero. hence

json.weather[0]


#7

It gives undefined and bunch of errors in the console.


#8

if you want specific stuff from an object, you use the dot notation. for arrays, you use an index.

json.weather[0] is json (the data in its entirety) > weather property of the json object > weather is an array, and you are getting the 0th index

or json.weather which will return an array defined at the weather property

here is more info about objects

and arrays


#9

Hmm, It works now … seems I was confused about the hierarchical data structure of json object