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

172
Vistas
JSON string won't print to console

I have this service:

getCert(p: string): Promise<string> {
  return ApiService.getData(this.apiUrl + p + this.certEndpoint).then(
    (response) => response.data
  );
}

This is an example of data:

{
    "state": "success",
    "message": "Message received."
}

If I return response.data.state or response.data.message I get the relevant value.

If I call it with this:

async componentDidMount() {
    const queryString = require('query-string');
    const parsed = queryString.parse(location.search);
    return this.docListingService.getPks(parsed.policy).then(async pks => {
        this.setState({ isLoading: false, packs });
        this.certService.getCert(parsed.policy).then( response => {
            console.log('RESPONSE: ' + response);
        });
        return pks;
    }).catch((error) => {
        this.loggingService.logError('Error returning Docs ' + error);
        this.setState({ errorOccured: true});
    });
}

response is a string but my consle.log prints RESPONSE [object Object]. I tried console.log('RESPONSE: ' + response.state); and console.log('RESPONSE: ' + response.message); but they error. As does:

console.log('RESPONSE: ' + JSON.parse(response));

How do I resolve this?

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

0

console.log() accepts as many arguments as you like. So you can just use it like this:

console.log('response ', response)

If you want to log multiple variables, you can do it like this:

console.log(variable1, variable2, variable3, 'some string', variable4);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Just use:

JSON.stringify(response)

This will show the Object structure as string value.

about 4 years ago · Juan Pablo Isaza Denunciar

0

you have a bug in console.log of your code, you are trying to concat a string and json object. you can try this code

console.log('response ', JSON.parse(response));

//or

console.log('response ', JSON.parse(response).data.message);

//or

console.log('response ' + JSON.parse(response).data.message);
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