簡體   English   中英

如何JSONify在typescript中定義的代碼

[英]how to 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 );
  }
}

我想將上面的typescript代碼更改為JSON。

您可以使用JSON.stringify(new ArticleListitem('x'))方法來獲取json。 請參閱 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM