将循环结构转换为 JSON
Converting Circular Structure to JSON
我有两种对象,Beam 和 Sample。样本包含 2 个光束,我有一个样本数组。我需要将数组存储到本地存储中,所以我正在调用 localStorage["samples"] = JSON.stringify(samples);
但我得到错误 "Converting Circular Structure to JSON"。我的对象不包含自身。我也尝试用 1 个 beam
对象替换 samples
对象,但得到了同样的错误,并且 Beam 中只有整数和字符串值。
编辑
这是对象。
function FlexuralStrengthT97(result, method, beam1, beam2, waitForCuring, averageBeams) {
this.Result = result;
this.Method = method;
this.Beam1 = beam1;
this.Beam2 = beam2;
this.WaitForCuring = waitForCuring;
this.AverageOfBeams = averageBeams;
return this;
}
function FSBeam(testingMachineId, beamAge, widthU, widthC, widthL, widthAverage, depthR, depthC, depthL, depthAverage, maxLoad, fs, psi, breakOutside) {
this.TestingMachineId = testingMachineId;
this.BeamAge = beamAge;
this.WidthUpper = widthU;
this.WidthCenter = widthC;
this.WidthLower = widthL;
this.WidthAverage = widthAverage;
this.DepthRight = depthR;
this.DepthCenter = depthC;
this.DepthLeft = depthL;
this.DepthAverage = depthAverage;
this.MaxLoad = maxLoad;
this.FS = fs;
this.PSI = psi;
this.BreakOutside = breakOutside;
return this;
}
这些似乎是构造函数,请确保将它们与 new
关键字一起使用:
var beam1 = new FSBeam();
var flex = new FlexuralStrengthT97();
否则,this
将是 window
而不是实例范围。
我有两种对象,Beam 和 Sample。样本包含 2 个光束,我有一个样本数组。我需要将数组存储到本地存储中,所以我正在调用 localStorage["samples"] = JSON.stringify(samples);
但我得到错误 "Converting Circular Structure to JSON"。我的对象不包含自身。我也尝试用 1 个 beam
对象替换 samples
对象,但得到了同样的错误,并且 Beam 中只有整数和字符串值。
编辑
这是对象。
function FlexuralStrengthT97(result, method, beam1, beam2, waitForCuring, averageBeams) {
this.Result = result;
this.Method = method;
this.Beam1 = beam1;
this.Beam2 = beam2;
this.WaitForCuring = waitForCuring;
this.AverageOfBeams = averageBeams;
return this;
}
function FSBeam(testingMachineId, beamAge, widthU, widthC, widthL, widthAverage, depthR, depthC, depthL, depthAverage, maxLoad, fs, psi, breakOutside) {
this.TestingMachineId = testingMachineId;
this.BeamAge = beamAge;
this.WidthUpper = widthU;
this.WidthCenter = widthC;
this.WidthLower = widthL;
this.WidthAverage = widthAverage;
this.DepthRight = depthR;
this.DepthCenter = depthC;
this.DepthLeft = depthL;
this.DepthAverage = depthAverage;
this.MaxLoad = maxLoad;
this.FS = fs;
this.PSI = psi;
this.BreakOutside = breakOutside;
return this;
}
这些似乎是构造函数,请确保将它们与 new
关键字一起使用:
var beam1 = new FSBeam();
var flex = new FlexuralStrengthT97();
否则,this
将是 window
而不是实例范围。