gpt4 book ai didi

javascript - 将循环结构转换为 JSON

转载 作者:行者123 更新时间:2023-12-03 08:38:57 25 4
gpt4 key购买 nike

我有两种对象,Beam 和 Sample。样本包含 2 个光束,并且我有一系列样本。我需要将数组存储到本地存储中,因此我调用 localStorage["samples"] = JSON.stringify(samples); 但收到错误“将循环结构转换为 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 而不是实例范围。

关于javascript - 将循环结构转换为 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33111988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com