相关疑难解决方法(0)

JSON.stringify,避免TypeError:将循环结构转换为JSON

我有一个大对象,我想转换为JSON并发送.但它具有圆形结构.我想抛出任何存在的循环引用并发送任何可以进行字符串化的内容.我怎么做?

谢谢.

var obj = {
  a: "foo",
  b: obj
}
Run Code Online (Sandbox Code Playgroud)

我想将obj字符串化为:

{"a":"foo"}
Run Code Online (Sandbox Code Playgroud)

javascript json node.js

608
推荐指数
10
解决办法
67万
查看次数

在玩笑单元测试角度中显示正确的错误

我正在 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)

jestjs angular cypress

7
推荐指数
1
解决办法
1485
查看次数

标签 统计

angular ×1

cypress ×1

javascript ×1

jestjs ×1

json ×1

node.js ×1