[TypeScript] JSON对象转TypeScript对象范例

[TypeScript] JSON对象转TypeScript对象范例

Playground

Samples

class DataTable {

    public columns: Array<string>;

    public rows: Array<DataRow>;
}

class DataRow {

    public cells: Array<string>;
}

class Test {

    public jsonObject =
    {
        "columns": ["ColumnA", "ColumnB", "ColumnC"],
        "rows":
        [
            { "cells": ["A1", "B1", "C1"] },
            { "cells": ["A2", "B2", "C2"] }
        ]
    };

    public run() {
        var x = (<DataTable>this.jsonObject);
        x.columns.push("ColumnD");
        alert(x.columns.length);
    }
}

var test = new Test();
test.run();
posted @ 2015-07-07 11:40  Clark159  阅读(14242)  评论(0编辑  收藏  举报