import { _decorator, Component, JsonAsset} from 'cc';
const { ccclass, property, type, string, integer} = _decorator;
@ccclass('D')
export class D {
@string
public id;
@integer
public maxStackSize;
@string
public displayName;
@string
public itemType;
}
@ccclass('E')
export class E {
@type([D])
public data : D[];
}
@ccclass('A')
export class A extends Component {
@type(JsonAsset)
public myJson : JsonAsset;
@type(E)
public myE;
protected start(): void {
this.myE = this.myJson.json as E;
}
}
I have a json and a class like above. Upon running it, there is no data. How should i do to make it correctly ? I want to view the parsed data in editor.
I’m still new to CC, but I’m interested in this point, and at the same time it seems to me that there is no way to reflect JSON directly into a class instance…what JsonAsset does is simply (quote from the API): “It will automatically parse the json to a JS object.”