在Angular2(TypeScript)中,我有一个包含以下构造函数的类:
export class DataModel {
constructor(public date_of_visit: string,
public gender: boolean,
public year_of_birth: number,
public height: number,
public weight: number){}
}
我有以下JSON对象:
json = {"date_of_visit": "23/09/2016", "gender": 1, "year_of_birth": 1975, "height":185, "weight": 85}
问题:使用JSON数据作为输入创建DataModel实例的最简单方法是什么?像new DataModel(**json)
答案 0 :(得分:1)
对于编译时转换,这将执行:
let dataModel = {"date_of_visit": "23/09/2016", "gender": 1, "year_of_birth": 1975, "height":185, "weight": 85} as DataModel;
答案 1 :(得分:0)
施法会让你通过:
Regex.Matches("hnfdjkkedjjykukyukrtrnrkkkkt", "[k]").Count