Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
quiero obtener json de esta promesa, ¿cómo puedo hacer eso?
var url = "https://www.metaweather.com/api/location/2471217/#"; let promise = new Promise((resolve, reject) => { fetch(url) .then(function (response) { return response.json(); } ) .then(function (json) { resolve(JSON.stringify(json)) }) }) promise.then((message) => { console.log(message) }).catch((message) => { console.log(message) })

Quiero obtener json como cadena. gracias chicos

ps soy un novato para JS

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

fetch ya devuelve una promesa. No es necesario utilizar el constructor Promise . Si desea obtener la respuesta como texto, simplemente puede llamar a response.text() , no a response.json() :

 fetch(url) .then(response => response.text()) .then(message => console.log(message)) .catch(error => console.error(error))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!