Need help parsing an http request in the following format:
[
{
"id": 1,
"date": "2022-01-13T00:00:00.000+00:00",
"time": "2022-01-13T21:21:21.000+00:00",
"office": {
"id": 2,
"description": "Office2",
"phone": "123456789",
"enabled": 1
},
"officeDescr": "Office2",
"reason": 2,
"reasonDescr": "Studies",
"file": "1.pdf",
"status": 0,
"userIn": {
"username": "name",
"password": "'$2a$04$DR/f..s1siWJc8Xg3eJgpeB28a4V6kYpnkMPeOuq4rLQ42mJUYFGC",
"enabled": 1,
"firstname": "fname",
"lastname": "lanme",
"asm": 123,
"office": 2,
"authorities": [
{
"authority": "ROLE_POLITIS"
}
]
},
"commentIn": null,
"userValid": null,
"commentValid": null,
"userApproved": null,
"commentApproved": null
},
...
]
Having trouble extracting the username from the userIn object using:
this.applicationService.get().subscribe(
(applications) => (console.log(applications.body.find(s=>s.userIn).userIn)));
Is there a way to access the attributes separately?
Attempted adding brackets []
to
applications.body.find(s=>s.userIn).userIn
but always returns undefined.
EDIT
Utilizing a service that relies on HttpClient
to fetch data from the Backend server
getPostponements(): Observable<HttpResponse<Application[]>> {
const url = `${this.apiUrl2}/postponements`;
return this.http.get<Application[]>(url,{ observe: 'response' })
}
The applications
type within the .subscribe
is
HttpResponse<Application[]>
Included a Model named Application.ts:
export interface Application {
id?: number;
date: string;
time: string;
reason: number;
reasonDescr: string;
office: number;
officeDescr: string;
file: string;
userIn: number;
commentIn: string;
userValid: string;
commentValid: string;
userApproved: string;
commentApproved: string;
status: number;
}