【发布时间】:2017-03-03 11:14:30
【问题描述】:
假设为这个 JSON 字符串:
[
{
"id": 1,
"text": "Jon Doe"
},
{
"id": 1,
"text": "Pablo Escobar"
}
]
让我们成为这个班级:
export class MyObject{
id: number;
text: string;
}
如何将此 JSON 字符串转换为 MyObject 列表?
如果我这样做:
console.log(<MyObject[]>JSON.parse(json_string));
它返回Object 的列表而不是MyObject 的列表
【问题讨论】:
标签: json object typescript casting