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

190
Visualizações
unexpected end of the JSON endpoint

I am working on the quiz app https://mcqpsm.online/ trying to achieve quiz count- how many times quiz have been taken, data comes from the back4app backend. it works fine until I have 50 total quizzes, now app breaks with the error as no of quiz increased to 59. everything works fine except the in quiz preview https://mcqpsm.online/browse it throws error that unexpected end of json input.

I tried console.log error and found that it is this code throwing error

export async function getQuizzes() {
const quizzes = (await api.get(host + '/classes/Quiz')).results; // empty array if none

const timesTaken = quizzes.length ? await getSolutionsCount(quizzes.map((q) => q.objectId)) : null;

quizzes.forEach((q) => (q.taken = timesTaken[q.objectId]));

return quizzes.length ? quizzes : null;

}

when I comment out the it works fine:

// const timesTaken = quizzes.length ? await getSolutionsCount(quizzes.map((q) => q.objectId)) : null;

// quizzes.forEach((q) => (q.taken = timesTaken[q.objectId]));

but now it does not shows how many times quiz taken enter image description here

function for quiz count is as follows

export async function getSolutionsCount(quizIds) {
const query = JSON.stringify({ $or: quizIds.map((id) => ({ quiz: createPointer('Quiz', id) })) });

const solutions = (await api.get(host + '/classes/Solution?where=' + encodeURIComponent(query))).results; // empty array if none

if (solutions.length === 0) {
    return quizIds.reduce((a, c) => {
        if (!a[c]) {
            a[c] = 0;
        }
        return a;
    }, {});
}
return solutions.reduce((a, c) => {
    const id = c.quiz.objectId;
    if (!a[id]) {
        a[id] = 0;
    }
    a[id]++;
    return a;
}, {});

}

thanks in advance !

about 4 years ago · Juan Pablo Isaza
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