Looking to convert a JSON array into a TypeScript variable array.
The JSON data retrieved from http://www.example.com/select.php:
{
"User":[
{"Name":"Luca M","ID":"1"},
{"Name":"Tim S","ID":"2"},
{"Name":"Lucas W","ID":"3"}
]
}
Desired output array:
this.items = [
'Luca M',
'Tim S',
'Lucas W'
];
UPDATE:
Current code snippet:
this.http.post('http://www.example.com/select.php', creds, {
headers: headers
})
.map(res => res.json().User)
.subscribe(
data => this.data = data.User.map(user => user.Name),
err => this.logError(err),
() => console.log('Completed')
);
this.items = this.data;
Error message received:
Cannot read property 'map' of undefined
Any suggestions on how to resolve this issue?
Thanks and regards,