0

I feel kinda dumb asking this. Because I was able to parse Maps and Lists from the api but I have no idea how to use something as simple as a double from the same api.

I simply want to make a

double yld;

from this api link,

https://sandbox.iexapis.com/stable/data-points/market/DGS10?token=Tsk_38ddda0b877a4510b42a37ae713cdc96

1 Answer 1

1

The response body is a String so you'll have to parse it into a double using double.parse()

getYld() async {
  var url = 'https://sandbox.iexapis.com/stable/data-points/market/DGS10? 
  token=Tsk_38ddda0b877a4510b42a37ae713cdc96';
  var res = await http.get(url);
  if (res.statusCode == 200) {
     double yld = double.parse(res.body);  // parse the double here
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I get an error "The await expression can only be used in an async function". I am guess your put this inside a Future<double> >
You have to create an async function for this. i updated the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.