Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Json parse error on api call react-native

I have this Ajax request function.

export async function fetchAllCoinsPromise() {
  const apiCall = await fetch('https://api.coincap.io/v2/assets');
  const jsonResult = await apiCall.json();

  return jsonResult;
}

I call it like this:

  const fetchCoins = () => {
fetchAllCoinsPromise()
  .then(res => console.log(111))
  .catch(err => {
    console.log('err', err);
    fetchCoins();
  });
 };

the reason why I'am doing this recursion is because sometimes I'm getting this strange error: SyntaxError: JSON Parse error: Unexpected identifier "You"] and I thought the async recursion would solve the issue and it does but I am not sure if this is the best solution in case of time complexity. Any suggestions please?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use a filter if you want. It might be a hacky solution but it works.

An example might look like:


if(jsonResult.startsWith('Y')){
  console.log("Error: " + jsonResult);
  tryYourCallAgain();
  } else {
  return jsonResult;
  }

You could use any filter that would catch the error like typeof, includes, etc. Whatever is best in your case.

Pardon if this code is sloppy as I'm relatively new to Javascript, but this worked for me in a similar case. Hope it helps!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda