gpt4 book ai didi

javascript - 使用 JSON.stringify() 将 JSON 对象转换为字符串时出现循环对象值错误

转载 作者:行者123 更新时间:2023-12-01 01:44:20 29 4
gpt4 key购买 nike

我有一个格式为的 JSON 对象:

obj { 
name: "abc" ,
entriesList : "list of entry obj" ,
propertiesList : "list of properties obj"
};

其中entry也是另一个对象

entry { 
info : "data obj" ,
age : "15" ,
subjects : "5"
}
properties {
a : "a" ,
b : "b"
}
data {
c : "c" ,
d : "d"
}

使用JSON.stringify()它给出错误

cyclic object value

我应该如何将我的对象转换为 JSON 字符串?

最佳答案

我在您的示例中看不到循环,但其想法是不在您的对象中包含循环引用。我的意思是避免这样的事情:

var a = {}, b = {};
a.child = b;
b.child = a; //This will cause a cyclic reference when calling JSON.stringify both on a and b object

关于javascript - 使用 JSON.stringify() 将 JSON 对象转换为字符串时出现循环对象值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30449083/

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