[TypeScript] TypeScript对象转JSON字符串范例

news/2025/2/26 13:35:11

[TypeScript] TypeScript对象转JSON字符串范例

Playground

  • http://tinyurl.com/njbrnrv

Samples

class DataTable {

    public columns: Array<string> = new Array<string>();

    public rows: Array<DataRow> = new Array<DataRow>();
}

class DataRow {

    public cells: Array<string> = new Array<string>();
}

class Test {

    public run() {

        var table = new DataTable();
        table.columns.push("ColumnA");
        table.columns.push("ColumnB");
        table.columns.push("ColumnC");

        var row1 = new DataRow();
        row1.cells.push("A1");
        row1.cells.push("B1");
        row1.cells.push("C1");
        table.rows.push(row1);

        var row2 = new DataRow();
        row2.cells.push("A2");
        row2.cells.push("B2");
        row2.cells.push("C2");
        table.rows.push(row2);

        alert(JSON.stringify(table));
    }
}

var test = new Test();
test.run();

转载于:https://www.cnblogs.com/clark159/p/4626864.html


http://www.niftyadmin.cn/n/543232.html

相关文章

自定义RecyclerView,实现ListView、GridView、ViewPager功能

CommonRecyclerView 通用的RecyclerView&#xff0c;实现了RecyclerView、GridView、ViewPager功能 How to To get a Git project into your build: Step 1. Add the JitPack repository to your build file gradle maven sbt leiningen Add it in your root build.gradle …

使用PowerShell Direct从Hyper-V主机管理VM

使用PowerShell Direct从Hyper-V主机管理VM借助PowerShell Direct&#xff0c;我们可以无需担心网络或防火墙限制&#xff0c;因为无论网络还是远程管理配置&#xff0c;它都可以工作。那么&#xff0c;很多朋友都会问既然不是通过网络和防火墙那是通过什么样的方式连接的呢&am…

MeteoInfoLab脚本示例:计算涡度、散度

用U/V分量数据计算涡度和散度&#xff0c;计算涡度的函数是hcurl&#xff0c;计算散度的函数是hdivg&#xff0c;参数都是U, V。脚本程序&#xff1a; f addfile(D:/Temp/GrADS/model.ctl) u f[U][0,0,:,:] v f[V][0,0,:,:] vort hcurl(u, v) divg hdivg(u, v) axesm() ml…

Acrtivity和Application的Context的区别

1. Applicaiton的构造只有一个 public Application() {super(null); } 其父类是ContextWrapper&#xff0c;构造只有一个 Context mBase;public ContextWrapper(Context base) {mBase base; } 由此可见&#xff0c;super里面传进去的是null&#xff0c;Applicaiton是不存在…

一步一步实现一个符合PromiseA+规范的Promise库(1)

今天我们来自己手写一个符合PromiseA规范的Promise库。大家是不是很激动呢&#xff1f;&#xff1f; 才没有。。 我们都知道。在现在的前端开发中&#xff0c;Promise这个东西基本上所有的开发中都会用到。 那必然有些萌新就会问了&#xff0c;Promise到底是个什么东西呢。 按照…

jQuery发送ajax请求三种方式

<button>点击发送ajax get请求</button> <button>点击发送ajax post请求</button> <button>点击发送通用的ajax请求</button> <script type"text/javascript" src"jquery-1.8.3.min.js"></script> <sc…

ffmpeg命令高级进阶

转自&#xff1a;https://www.liangzl.com/get-article-detail-8191.html FFMPEG拥有强大的视频处理能力&#xff0c;可惜的是有很多人不知道如何使用。本文深入介绍如何用编译好ffmpeg.exe程序处理视频&#xff0c;既有常用的简单的处理&#xff0c;也有一些比较少见的高大上…

论java虚拟类和接口的区别

如题&#xff1a;Abstract使数据成员虚拟化&#xff0c;而Interface则使方法成员虚拟化。转载于:https://www.cnblogs.com/shoubianxingchen/p/4633311.html