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

99
Vistas
how to assign server response to object

i am trying to assign server response to an object, without success.

pls guide how to save this response to object?, have i defined user model correctly?

heres my user model

interface BelongsTo {
 class_id: string;
 section_id: string;
}
interface Userinfo {
 _id: string;
 name: string;
 user_id: string;
 roles: string[];
 belongs_to: BelongsTo;
}

export interface IUser {

 user: Userinfo
 token: string
}

and the response from server is

{
message: "Success"
user:{
    "_id": "60fbb4ec93eb4604658fc543",
    "name": "Irfan",
    "user_id": "irfan_123",
    "roles": [
        "student"
    ],
    "belongs_to": {
        "class_id": "60fbb3bb93eb4604658fc541",
        "section_id": "60fbb3eb93eb4604658fc542"
    },
    "created_at": "2021-07-24T06:36:28.006Z",
    "updated_at": "2021-07-24T06:36:28.006Z"
},
token: "eyJhbGciOiJIUzI1NiIs.5cCI6IkpXVCJ9.eyJCI6IkpXVCJCI6IkpXVCJ"
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

What is the name of the variable you have used as a server response? Is it something like myResponse? If so, you can access the property user inside that variable and finally store it in your desired variable this.user.

this.user = myResponse.user; // myRespone is the variable you used to capture the server response and then you are accessing the user property.
about 4 years ago · Juan Pablo Isaza Denunciar

0

use this:

let data = JSON.parse(response);
let userInfo = JSON.parse(data.user);
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