javascript - 如何对打字稿中定义的代码进行 JSON 化
问题描述
有没有办法对打字稿中定义的代码进行 JSON 化?
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 );
}
}
我想将上面的打字稿代码更改为 JSON。
解决方案
您可以使用JSON.stringify(new ArticleListitem('x'))
方法来获取json。参考 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
推荐阅读
- realm - 无法通过 REST 管理 API 创建 Keycloak 领域:不支持的媒体类型
- emoji - 使用 ICU4C 验证表情符号序列
- webview - alertdialog 位于 webview 下方,因此用户看不到 alertdialog
- java - 如何确保我的重构不会改变代码的流程?
- javascript - 用js-xlsx导出.xlsx文件时如何根据内容设置整列的宽度?
- excel - 使用公式从同一单元格中提取多个字符串
- mysql - docker compose:spring boot连接到mysql数据库被拒绝
- node.js - Hyperledger“智能合约”可以在该州拥有多个集合吗?
- excel - 从 .Interior.ColorIndex 转换为颜色名称 - VBA
- ruby - Docusign APi with RUby:有没有办法下载包含所有选项卡内容的文档