I am trying to extract the `s_id` field from this JSON data:
{
"StatusCode": 0,
"StatusMessage": "OK",
"StatusDescription": [
{
"s_id": "11E8C70C8A5D78888E6EFA163EBBBC1D",
"s_serial": "PkMGo",
"active": 0,
},
{
"s_id": "11E8C70FB9D10DB38E6EFA163EBBBC1D",
"s_serial": "UgooX",
"active": 0,
},
{
"s_id": "11E8C7179F85836D8E6EFA163EBBBC1D",
"s_serial": "IiLnM",
"active": 0,
}, .....
{
"s_id": "11E8C71905123F1A8E6EFA163EBBBC1D",
"s_serial": "LVpcP",
"active": 0,
}
}]}
Despite my efforts, I am unable to find it and keep getting 'undefined'.
sensors: Sensors[]=[];
hbp: HBP;
sensor: Sensors;
this.ss.getAllS().subscribe(
sensors => {
this.sensors = sensors
let ss = this.sensors.find(x => x.s_id === this.hbp.s_id);
console.log(ss)
if (ss) {
this.selectedSensor = ss.s_id
}
}
);
In addition,
selectedSensor : string = this.sensors.filter(
x => x.s_id === this.sensor.s_id[0])
.map(y => y.s_serial).join('');
I believe there is an issue with this line:
let ss = this.sensors.find(x => x.s_id === this.hbp.s_id);
This may be because the `hbp` variable returns the following JSON:
active: 0
homebox_id: "11E8C71154CC8C188E6EFA163EBBBC1D"
sensors: Array(2)
0: {s_serial: "s_id", s_id: "11E8C70C8A5D78888E6EFA163EBBBC1D"}
1: {s_serial: "UgooX", s_id: "11E8C70FB9D10DB38E6EFA163EBBBC1D"}
Thus, the search might be conducted within these sensors.
The selectedSensor
variable is utilized in the HTML code as follows:
<input formControlName="s_id" type="text" placeholder="Select " [(ngModel)]="selectedSensor" aria-label="Number" matInput
[matAutocomplete]="auto">
How can I retrieve the required data?
Any suggestions or ideas would be greatly appreciated. Thank you!