Reputation: 3705
I need to get csv data from an url, which returns a string. When I call res.json()
it throws an error that unexpected token D in json at position 0 (the first letter of the string). Why? The response is exactly what I want, and I just want to get it.
fetch("https://cors-anywhere.herokuapp.com/http://www.football-data.co.uk/mmz4281/1718/I1.csv")
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.log(err))
Upvotes: 0
Views: 140
Reputation: 6169
Because you are requesting a csv file so it's not a json. Use res.text() to retrieve the text instead.
Upvotes: 4