Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

92
Views
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 answers
Answer question

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 Report

0

use this:

let data = JSON.parse(response);
let userInfo = JSON.parse(data.user);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!