Reach Fetching Datas from external API

Hi guys, I got a small problem.
I would like to get with an external API some json datas but there is a trap.

{
"coord":{"lon":-73.57,"lat":45.5},
"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],
"base":"stations","main":{"temp":22.91,"pressure":1010,"humidity":60,"temp_min":22,"temp_max":24},
"visibility":48279,
"wind":{"speed":7.7,"deg":270,"gust":11.3},
"clouds":{"all":20},
"dt":1526320800,
sys":"type":1,"id":3829,"message":0.0902,"country":"CA",
"sunrise":1526289839,"sunset":1526343480},
id":6077243,
"name":"Montreal","cod":200}

Thatā€™s the json data of a small weather API but i donā€™t even know how to get precisely a object like in Coord -> lon.

In my code I put :

	loadPosition(){
 
		this.geolocation.getCurrentPosition().then((resp) => {
		 // resp.coords.latitude
		 //let userPosition: LatLng = news LatLng(resp.coords.latitude,resp.coords.longitude);
		 //console.log(resp.coords.latitude + ' ' + resp.coords.longitude);\
		  this.lng = resp.coords.longitude;
			this.lat = resp.coords.latitude;
			this.test = this.Pro.getWeatherPerLatLng(this.lat,this.lng).subscribe((data: Weather) => this.weather.coord.lon = {lon: data["lon"],
		});
			console.log(this.test, 'Sortie de la fonction');
			console.log('Weather Object', this.weather);
		});

But i donā€™t know how to get the ā€œLONā€ in 'ā€˜Coordā€™ā€¦

I created an interface like that

export interface Weather{
  coord: {
    lon: number,
    lat: number
  },
  weather: [
    {
      id: number,
      main: String,
      description: String,
      icon: String
    }
  ],
  base: String,
  main: {
    temp: number,
    pressure: number,
    humidity: number,
    temp_min: number,
    temp_max: number
  },
  visibility: number,
  wind: {
    speed: number,
    deg: number
  },
  clouds: {
    all: number
  },
  dt: number,
  sys: {
    type: number,
    id: number,
    message: number,
    country: String,
    sunrise: number,
    sunset: number
  },
  id: number,
  name: String,
  cod: number
}

Thanks for your time ā€¦

See:

Hi, thanks for your reply but if iā€™m doing a parse, shoud I delete the line with the subscribe ?

JSON data is normally accessed in Javascript through dot notation.

See: How To Work with JSON in JavaScript | DigitalOcean

1 Like

Yes i do but always saying ā€œUnable to assign type {lon: any} to type numberā€
I think iā€™m doing it really wrongā€¦