Let be this JSON string:
[
{
\"id\": 1,
\"text\": \"Jon Doe\"
},
{
\"id\": 1,
\"text\": \"Pablo Escobar\"
}
]
You will need to create a constructor for your class, and call it for each item in the list you receive.
export class MyObject{
constructor(public id: number, public text: string) { }
}
let data = [
{
"id": 1,
"text": "Jon Doe"
},
{
"id": 1,
"text": "Pablo Escobar"
}
];
let objects = data.map(o => new MyObject(o.id, o.text));
You can check it out in the playground here.