码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-07-07 12:55:01      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:

[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();

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

标签:

原文地址:http://www.cnblogs.com/clark159/p/4626504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!