Estoy tratando de analizar estos datos de Marvel API usando JSON.parse(); pero no soy capaz. Estoy usando Node.js.
Aquí está el código que estoy usando para obtener datos de la API:
app.post("/", function(req, res) { const nameStartsWith = req.body.superhero; const ts = "timestamp"; const apikey = "myPublicKey"; const hash = "md5 digest"; const url = "http://gateway.marvel.com/v1/public/characters?ts=" + ts + "&apikey=" + apikey + "&hash=" + hash + "&nameStartsWith=" + nameStartsWith; http.get(url, function(response) { response.on("data", function(data) { // getting error here console.log(JSON.parse(data)); }); }); });A continuación se muestran los datos JSON incompletos:
{"code":200,"status":"Ok","copyright":"© 2022 MARVEL","attributionText":"Data provided by Marvel. © 2022 MARVEL","attributionHTML":"<a href=\"http://marvel.com\">Data provided by Marvel. © 2022 MARVEL</a>","etag":"08aea880d9e638f37cf6011d63a936fbe3f82f22","data":{"offset":0,"limit":20,"total":5,"count":5,"results":[{"id":1009718,"name":"Wolverine","description":"Born with super-human senses and the power to heal from almost any wound, Wolverine was captured by a secret Canadian organization and given an unbreakable skeleton and claws. Treated like an animal, it took years for him to control himself. Now, he's a premiere member of both the X-Men and the Avengers.","modified":"2016-05-02T12:21:44-0400","thumbnail":{"path":"http://i.annihil.us/u/prod/marvel/i/mg/2/60/537bcaef0f6cf","extension":"jpg"},"resourceURI":"http://gateway.marvel.com/v1/public/characters/1009718","comics":{"available":2549,"collectionURI":"http://gateway.marvel.com/v1/public/characters/1009718/comics","items":[{"resourceURI":"http://gateway.marvel.com/v1/public/comics/41113","name":"5 Ronin (Hardcover)"},{"resourceURI":"http://gateway.marvel.com/v1/public/comics/38756","name":"5 Ronin (2010) #1"Está mostrando este error en mi hiper terminal:
SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at IncomingMessage.<anonymous> (C:\Users\mishr\OneDrive\Desktop\MarvelComics-Project\app.js:79:24)