Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda