Here is the json file that i want to parse:
{
"Meta Data": {
"1. Information": "Weekly Adjusted Prices and Volumes",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2020-03-25",
"4. Time Zone": "US/Eastern"
},
"Weekly Adjusted Time Series": {
"2020-03-25": {
"1. open": "137.0100",
"2. high": "154.3300",
"3. low": "132.5200",
"4. close": "146.9200",
"5. adjusted close": "146.9200",
"6. volume": "235583286",
"7. dividend amount": "0.0000"
},
"2020-03-20": {
"1. open": "140.0000",
"2. high": "150.1500",
"3. low": "135.0000",
"4. close": "137.3500",
"5. adjusted close": "137.3500",
"6. volume": "421347734",
"7. dividend amount": "0.0000"
},
}
I just wanted to get the date, open, and close. I tried finding stuff online but still was unable to do so.
Here is my TimeSeries class:
class TimeSeries {
final String date;
final double open;
final double close;
TimeSeries({this.date, this.open, this.close});
factory TimeSeries.fromJson(Map<String, dynamic> json) {
return TimeSeries(
date: json[''],
open: double.parse(json['1. open']),
close: double.parse(json['4. close']),
);
}
}
And these are my function for now:
Future getTimeSeries(String stock) async {
print("Starting get request");
http.get("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo").then((res){
print("received response.");
var resObj = json.decode(res.body);
}).catchError((e) {
print("Failed to get response.");
});
}