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

183
Visualizações
assign json model to in javascript

I want to send a request to another API to get list of currency prices.

 https.get(this.baseUrl, (response) => {
                response.on('data', async (chunk) => {
                model = JSON.parse(JSON.stringify(chunk.toString('utf-8')));
      })
   });

response :

    {
      "success":true,
      "timestamp":1641994743,
      "base":"EUR",
      "date":"2022-01-12",
      "rates":{
        "AED":4.184454,
        "AFN":120.094117,
        "ALL":122.214122,
        "AMD":548.537072,
        "ANG":2.052899,
        "AOA":609.048742
         }
    }

I got array buffer and I use this command to convert that to a string model :

chunk.toString('utf-8')

when I use JSON.parse(chunk.toString('utf-8')) it show me this error :

UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input

and when I want to use this code :

model = JSON.parse(JSON.stringify(chunk.toString('utf-8')));

I can not access to model property . for example I an not access to model.success or model['success'] it show me undefined.

now whats the problem ? how can I solve this problem ?

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