我有一个大对象,我想转换为JSON并发送.但它具有圆形结构.我想抛出任何存在的循环引用并发送任何可以进行字符串化的内容.我怎么做?
谢谢.
var obj = {
a: "foo",
b: obj
}
Run Code Online (Sandbox Code Playgroud)
我想将obj字符串化为:
{"a":"foo"}
Run Code Online (Sandbox Code Playgroud) 我正在 NX angular 工作区中编写单元测试。有时它会给出这样的错误:
(node:15320) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'element' -> object with constructor 'Object'
| property 'componentProvider' -> object with constructor 'Object'
--- property 'parent' closes the circle
at stringify (<anonymous>)
at writeChannelMessage (internal/child_process/serialization.js:117:20)
at process.target._send (internal/child_process.js:779:17)
at process.target.send (internal/child_process.js:677:19)
at reportSuccess (C:\Users\INFINTY\angular\nfx__1-sep\node_modules\jest-runner\node_modules\jest-worker\build\workers\processChild.js:67:11)
(node:15320) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a …Run Code Online (Sandbox Code Playgroud)