JSON-Objekt in TypeScript initialisieren
Ich bin neu in TypeScript und arbeite nicht mehr mit JSON. Ich muss ein einfaches JSON-Objekt erstellen und scheitere weiterhin daran. Hier sind meine ersten Versuche:
output: JSON; //declaration
this.output = {
"col1":{"Attribute1": "value1", "Attribute2": "value2", "Attribute3": "value3"},
"col2":{"Attribute1": "value4", "Attribute2": "value5", "Attribute3": "value6"},
"col3":{"Attribute1": "value7", "Attribute2": "value8", "Attribute3": "value9"}
}
Das geht nicht. Ich denke, ich sollte mit der JSON.stringify-Funktion arbeiten. Hier ist mein Versuch:
obj: any; //new object declaration
this.obj = {
"col1":{"Attribute1": "value1", "Attribute2": "value2", "Attribute3": "value3"},
"col2":{"Attribute1": "value4", "Attribute2": "value5", "Attribute3": "value6"},
"col3":{"Attribute1": "value7", "Attribute2": "value8", "Attribute3": "value9"}
}
this.output.stringify(this.obj);
Dadurch wird jedoch weiterhin TypeError aufgerufen. Um meine Frage zusammenzufassen: Wie erstelle und initialisiere ich ein JSON-Objekt in TypeScript?