Wednesday 25 March 2020

Collection of objects from response

I am trying to create a collection of objects from an axios get, but I'm not sure how to convert my json response data into the collection and what the best practices would be.Here is my code:class TimeSeries {constructor(Confirmed, CountryRegion, Date, Deaths, Lat, Long, ProvinceState, Recovered)  {this.Confirmed = Confirmed;this.CountryRegion = CountryRegion;this.Date = Date;this.Deaths = Deaths; this.Lat = Lat; this.Long = Long; this.ProvinceState =  ProvinceState;this.Recovered = Recovered;this.ActiveCases = confirmed - recovered - deaths;  }}This is where I get my data, but I don't know how to get the json into the class and also create a collection:async function getTimeSeries() {try {axios.responseType = 'json';const response = await axios.get( 'https://pkgstore.datahub.io/core/covid-19/time-series-19-covid-combined_json/data/845fcaa5cc5dac944cf798f2bc96c46f/time-series-19-covid-combined_json.json')    .then(function (response) {console.log(response.data);response.data      .forEach(({'Country/Region': CountryRegion, Date, Confirmed, Recovered, Deaths }) =>console.log(\${CountryRegion} : ${Date} active cases: ${Confirmed - Recovered - Deaths}`))     });`Any help is appreciated!

Submitted March 25, 2020 at 11:48PM by hololensful

No comments:

Post a Comment