When using the json.stringify method to convert a string, an error typeerror: converting circular structure to JSON
will be reported
Reason: there is a circular reference to itself in the object;
For example:
let test = { a: 1, b: 2 };
test.c = test; // Circular references
JSON.stringify(test); // report an error
Solution:
the following JSON_ STR
is the converted String of JSON. Stringify
var cache = [];
var json_str = JSON.stringify(json_data, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
return;
}
cache.push(value);
}
return value;
});
cache = null; //release cache
Read More:
- How to Solve Converting circular structure to JSON‘ Error
- How to Solve JS error: Unexpected end of JSON input,Unexpected token u in JSON at position 0
- [Solved] JSON.parse() Error: Unexpected end of JSON input
- [Solved] VS Code Error: Vetur can‘t find ‘tsconfig.json‘ or ‘jsconfig.json‘
- Json.parse: All Error & How to Solve Them
- [Go] Can structure/structure pointer be compared with operator == is not defined error
- [Solved] ajax Error: Uncaught SyntaxError: Unexpected end of JSON input
- [Solved] Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension
- Such a simple serialization system.text.json.serialization also reports an error?
- Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0
- [Solved] electron Package and Startup Error: Error: ENOENT: no such file or directory, open ‘xxx/manifest.json‘‘
- The vue3 project Error: Cannot find module’vue-loader-v16/package.json’
- [Solved] Error: Cannot find module ‘vue-template-compiler/package.json‘ Require stack:
- [Solved] ERROR Error: Cannot find module ‘vue-loader-v16/package.json‘
- [Solved] Prittier format code error: JSON Error in…
- [Solved] Error in created hook: “SyntaxError: Unexpected token o in JSON at position 1“
- Special JSON array of special bracket
- Golang: How to determine structure whether it is empty
- package.json Scripts configuration environment variable distinguishes development environment from production environment
- Uni-app Error when assigning a value to a component: [system] TypeError: Cannot read property ‘name‘ of undefined