我有这个对象,其中包含我想知道的关于锻炼的几乎所有内容。然而,当我对对象进行字符串化时,不会存储数组对象或其他东西。
这是我要字符串化的对象:
Object {name: "testWorkout", program: Array[4]}
name: "testWorkout"
program: Array[4]
first: Array[3]
slope: 0
speed: "medium"
time: 10
length: 3
__proto__: Array[0]
interval1: Array[4]
radio: "Time"
size: "33"
slope: "79"
speed: "fast"
length: 4
__proto__: Array[0]
interval2: Array[4]
radio: "Time"
size: "3322"
slope: "16"
speed: "medium"
length: 4
__proto__: Array[0]
last: Array[3]
slope: 0
speed: "medium"
time: 20
length: 3
__proto__: Array[0]
length: 4
__proto__: Array[0]
__proto__: Object
但相反,它字符串化很好,它确实字符串化为:
{"name":"testesr","program":[null,null,null,null]}
如何用纯 JavaScript 解决这个问题?所以没有JQuery?
这些是我的 stringify 和 read 方法:
function putInLocalStorage(){
console.log(JSON.stringify(workout));
localStorage.setItem('workout-'+workout.name, JSON.stringify(workout));
}
function readLocalStorage(){
var retrievedObject = localStorage.getItem('workout-'+workout.name);
console.log('retrievedObject: ', JSON.parse(retrievedObject));
}