I am getting a JSON object with a JSON.parse function. I am facing the problem of converting the object to Data
object. This is how Data
is declared (it is simplified and the methods are omitted):
export class Data {
private static _instance: AppData;
private projects?: Project[] = Array();
constructor() {
}
public static get Instance() {
//create singleton
}
}
export class Project {
projectID: string;
projectNumber: number;
projectName: string;
dateCreated: number;
thumbnail: string;
details?: Detail[] = [];
}
export class Detail {
detailID:string;
detailName: string;
detailNumber:number;
dateCreated:number;
textElements?: Text[];
}
export class Text {
text: string;
textSize: number;
transform: Transform[];
transiton: Transiton[];
}
export class Transiton{
name:string;
}
export class Transform{
name:string;
}
Silly me, tried to typecast the whole object with as
. Then I tried to write constructors, but it got terribly complicated due to each Data
object having an array of Project
objects, each project having an array of Detail objects... each detail having an array of Text
objects and so on.
Is there a better way of doing this instead of just creating a ton of nested loops?