Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

Json格式数据在浏览器中解析不成功

$
0
0

@445908669 写道:

var CharInfo1 = {
password: "",
nickname: "",
maxHisScore: 0,
maxHisKillCount: 0,
coin: 0,
skinVec: "",
curskin: 0,
headid: 0,
curLen: 0,
};

                CharInfo1.username = "username";
                CharInfo1.nickname = "nickname";
                CharInfo1.maxHisScore = 0;
                CharInfo1.maxHisKillCount = 0;
                CharInfo1.coin = 0;
                CharInfo1.curskin =0;
                CharInfo1.headid = 0;

                cc.sys.localStorage.setItem("cinfo0", JSON.stringify(CharInfo1));

切换场景后, cc.director.loadScene("ReadyGame");

var t = JSON.parse(cc.sys.localStorage.getItem("cinfo0"));
cc.log("++++++11+++++++++%s", t.username)

浏览器中报错
Uncaught TypeError: Cannot read property 'username' of null

在不切换场景的条件下是没问题的,只要换场景浏览器就报这个错

帖子: 2

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>