美文网首页
2018-09-11

2018-09-11

作者: 某人在 | 来源:发表于2018-09-11 16:47 被阅读5次

其实LayaBox加载Json还是蛮简单的,但是作为新手来说,其实也不容易,下面放出解决方法,在类比一下就知道有多容易了。 

新建laya.json文件放入到bin目录下

// laya.json{

    "name": "deng",

    "age": 17,

    "sex": "male",

    "phone:": "12345678"

}

// LayaSample.ts// 程序入口

class GameMain{

    constructor()

    {

        Laya.init(600,400);        Laya.loader.load("laya.json", Laya.Handler.create(this, this.onLoaded), null, Laya.Loader.JSON);    }

    private onLoaded() {

        var json: JSON = Laya.loader.getRes("laya.json");        console.log(json["name"]);        console.log(json["age"]);        console.log(json["sex"]);        console.log(json["phone"]);    }

}

new GameMain();

最后输出结果:

deng

17

male

12345678

相关文章

网友评论

      本文标题:2018-09-11

      本文链接:https://www.haomeiwen.com/subject/thiugftx.html