[英]how to to JSONify the code defined in typescript
Is there a way to JSONify the code defined in typescript? 有没有办法JSONify在typescript中定义的代码?
export type ArticleList = ArticleListItem[];
export class ArticleListItem {
title!: string;
date?: string;
key_type!: KeyTypes;
path!: string;
query: string = '';
constructor( item: ArticleListItem ) {
Object.assign( this, item );
}
}
I would like to change the above typescript code to JSON. 我想将上面的typescript代码更改为JSON。
You can use JSON.stringify(new ArticleListitem('x'))
method to get the json. 您可以使用
JSON.stringify(new ArticleListitem('x'))
方法来获取json。 Refer - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify 请参阅 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.