JavaScript exception: Uncaught TypeError: convert circular structure to JSON

Hava json object:

[#1={id:"2012-05-04", title:"Scheduled", start:(new Date(1336096800000)), source:{events:[#1#], className:[]}, _id:"2012-05-04", _start:(new Date(1336089600000)), end:null, _end:null, allDay:true, className:[]}] 

I am trying to execute it:

 var test = JSON.stringify(resourceVacation, censor(resourceVacation)); function censor(censor) { return (function() { var i = 0; return function(key, value) { if (i !== 0 && typeof(censor) === 'object' && typeof(value) == 'object' && censor == value) return '[Circular]'; ++i; // so we know we aren't using the original object anymore return value; } })(censor); } 

I use a censor as mentioned here: Chrome error sendrequest: TypeError: convert circular structure to JSON n

However, in the browser, I get the following exception:

Uncaught TypeError: convert circular structure to JSON

Here is the Java Script object: enter image description here

I got the previous JSON object using toSource () in Mozilla browser. Any idea how to fix this!

============================ UPDATE ====================== ===

Actually, I need to share scneio with you from the very beginning: 1 -Initially: I have a form, and in the end I create a java Script object that:

 #1=[{id:"2012-05-03", title:"Scheduled", start:(new Date(1336010400000)), source:{events:#1#, className:[]}, _id:"2012-05-03", _start:(new Date(1336003200000)), end:null, _end:null, allDay:true, className:[]}] 

This object is usually gated ... NOTE. This is typical of one that would later eliminate the exception .

2- Then I remove the objects from this array using:

 function deleteVacation(day) { for (var index = 0; index < resourceVacation.length; index++) { if (resourceVacation[index].id == day) resourceVacation.splice(index,1); } 

3. When I try to staple this array after deleting one object, I get the specified exception. So, anu ideas why this passed the first time and failed the 2nd time!

+6
source share
2 answers

You cannot JSON encode date objects.

From json.org : "The value can be a double-quoted string, or a number, or true, or false or zero, or an object or array. These structures can be nested."

+8
source

A problem is a source - an object that is a round link .

You must create a copy of the object without the original object.

How I solved the problem in FullCalendar.

+7
source

Source: https://habr.com/ru/post/915220/


All Articles