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

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

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 Relatório

0

use this:

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