//数组转json var arr = [1,2,3,4,5]; cc.sys.localStorage.setItem("key",
JSON.stringify(arr).toString()); //json转数组 var jsonStr =
cc.sys.localStorage.getItem("key"); var v = JSON.parse(jsonStr);
console.log(v[1], v[2]); //2 3
看下面的,比较神奇:
//数组转json var arr = ["1", "2",3,4,5]; var v1 = JSON.stringify(arr).toString();
//json转数组 var v = JSON.parse(v1); console.log(typeof v[1], typeof v[2]);
//string number反序列化后,竟然能识别出来类型。是string还是number