Recently, I received an API response that looks like this:
{
"status": "success",
"code": 0,
"message": "version list",
"payload" : "[{\"code\":\"AB\",\"short\":\"AB\",\"name\":\"Alberta\",\"country\":\"CA\"},{\"code\":\"BC\",\"short\":\"BC\",\"name\":\"British Columbia\",\"country\":\"CA\"}]"
}
I am facing a challenge where I need to extract the names of different objects from the payload. The issue is that the payload is returned as a string.
Despite my efforts to retrieve the object names, I have not been successful so far!
getAllPayload() {
this.myService.getpayload().subscribe(
data => {
this.values= data;
}
);
}
Additionally,
<select class="form-control">
<option *ngFor="let value of values.payload" >
{{value.name}}
</option>
</select>
Even attempting to parse the object using JSON.parse has been unsuccessful.
I'm stuck! Can anyone guide me on how to properly parse the payload and fetch the different names?