I have an JavaScript Object I want to serialize as a String:
key {...} Object
mandant "00001" String
personalNummer 600235 Number
First I used JSON2 where the return value was undefined. With JSON3 I get an TypeError and the comment in the Line of json3.js says:
// Cyclic structures cannot be serialized by `JSON.stringify`.
The problem seems to result from following lines in json3.js:
// Manually invoke the callback for the `constructor` property due to
// cross-environment inconsistencies.
if (isConstructor || isProperty.call(object, (property = "constructor"))) {
callback(property);
}
But there should be no cycle and I'm obvious not able to find out what the heck is going on.
When I create the Object by hand while debugging everything works fine.
So what could raise the error?
EDIT:
I succeeded to prepare a scenario to produce the error:
- It just happens in IE9 with compatibility modes IE7 and IE8 (Firefox 22 is fine, too)
- It just happens if a new window get opened which references the data from the opener window
*JSON_Cycle.html*:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://bestiejs.github.io/json3/lib/json3.js"></script>
<script>
var dataGlobal = {mandant: "Hallo Welt!", personalNummer: 123456};
$(function() {
window.open("JSON_Cycle_Popup.html", 'popup');
});
</script>
*JSON_Cycle_Popup.html*:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://bestiejs.github.io/json3/lib/json3.js"></script>
<script>
var dataGlobal = null;
$(function() {
dataGlobal = window.opener.dataGlobal;
alert(JSON.stringify(dataGlobal));
});
</script>