将json数据转换为angular 2+;
如何将此json文件中的数据转换为对象并在表中显示将json数据转换为angular 2+;,json,angular,typescript,Json,Angular,Typescript,如何将此json文件中的数据转换为对象并在表中显示 { "AndraPradesh": { "dData": { "Anantapur": { "notes": "", "history":2 "delta": { "force": 0 } } }, "sCode":
{
"AndraPradesh": {
"dData": {
"Anantapur": {
"notes": "",
"history":2
"delta": {
"force": 0
}
}
},
"sCode": "AP"
},
"Maharastra": {
"dData": {
"Pune": {
"notes": "",
"history":2
"delta": {
"force": 0
}
}
},
"sCode": "MH"
},
}
我创建了一个界面,如下所示
export interface DataInterface {
sName: string[];
dName: dData[];
sdCode: string;
}
export interface dData{
name: string;
notes: string;
history: number;
delta: Delta[];
}
interface Delta {
force: number;
}
我还创建了一个类文件。我不确定是否可以将上面的json转换为对象,以便将其分配给任何变量以进行进一步的操作我注意到您的DataInterface.dName是一个数组,同时它不是您显示的数组 请在此处检查答案:
让jsonObj:any=JSON.parse(employeeString);//首先将字符串转换为泛型对象
让员工:employee=jsonObj;
let jsonObj: any = JSON.parse(employeeString); // string to generic object first
let employee: Employee = <Employee>jsonObj;