1

My experience is low - I am attempting to stringy an object. It came back with a'expected array found object' type of error.

I attempted to track problem by curtailing the object creation function and retesting.

It worked fine till I got to a line that added a child to an existing Container object. The container had previously stringified ok and so did the child but after adding the child to the container the returned jsonObj was 'undefined'.

Any ideas? Should this have worked? Or would one expect problems?

I am using minified 0.8.1

<!DOCTYPE html>
html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo JSON Prob</title>
<script src="easeljs-0.8.1.min.js"></script>


<script>
  var dummy;

   var  aShape =new createjs.Shape();

 //jsonObjShape  = JSON.stringify(aShape);

   var aContainer = new createjs.Container();

   // jsonObjContainer  = JSON.stringify(aContainer);

  aContainer.addChild(aShape);

  jsonObjContainerWithChild  = JSON.stringify(aContainer);

 dummy =0; //put debugger breakpoint here

</script>
</head>
<body>

</body>
</html>
wrcstewart
  • 21
  • 3
  • Can you provide the relevant code and object? – trincot Feb 27 '19 at 12:19
  • The program is very complicated so I will try and and create a short program to demo the problem. – wrcstewart Feb 28 '19 at 11:30
  • Demo JSON Prob – wrcstewart Feb 28 '19 at 15:20
  • Oh dear it seems to have collapsed the code down. On inspecting the json object in the debugger it gives expected array found object error message. – wrcstewart Feb 28 '19 at 15:22
  • Click the edit link below your question, and enter it there. Make sure to select the code, and format it with the toolbar button (it indents the selection with 4 more spaces). – trincot Feb 28 '19 at 15:24
  • I've gone into the editor button below original question and pasted in the code. Then selected code and hit the code button. It doesn't carry out the ident but keeps telling me to indent it!! ? – wrcstewart Feb 28 '19 at 15:33
  • some of the code is html - is that allowed as code? – wrcstewart Feb 28 '19 at 15:34
  • Sure that is allowed. Make sure there is a blank line before and after the code before you hit that buttom. Alternatively, use an external editor and indent everything so every line has at least 4 spaces at its left, and copy/paste that in your question. – trincot Feb 28 '19 at 15:35
  • I ve tried the blank line and it didn't t work -I'll prepare it from my web storm. – wrcstewart Feb 28 '19 at 15:41
  • I was able to do it manually – wrcstewart Feb 28 '19 at 15:47
  • It looks like addChild method takes 2 parameters http://www.createjs.com/Docs/EaselJS/classes/Container.html – estinamir Feb 28 '19 at 16:52
  • Thanks for your thoughts but addChild can take one parameter. It is addChildAt that has to take two. The doc you link to confirms that it seems. – wrcstewart Feb 28 '19 at 17:40
  • You can [this](https://stackoverflow.com/a/21875464/10634638) (after include cycle.js) jsonObjContainerWithChild = JSON.stringify(JSON.decycle(aContainer)); – estinamir Mar 01 '19 at 02:37
  • Thanks - I'll give that try today – wrcstewart Mar 01 '19 at 09:14
  • Okay - considerable success with recycle approach. also with my original program. – wrcstewart Mar 01 '19 at 16:48
  • Okay - considerable success with recycle approach. also with my original program. But the JSON.parse does not return the container and child. And the retro cycle of course also subsequently fails. I'm wondering if you have used this and can advise on whether I need to use one of other parse routines that are supplied in the other GitHub files ? – wrcstewart Mar 01 '19 at 16:54
  • A further comment - it seems the result of the parse and retro cycle evaluate in the debugger to something that looks correct - with for example 1 child given - however it is nit being recognised as a Container object in calls such as destinationContainer.numChildren – wrcstewart Mar 01 '19 at 17:54
  • I haven’t use this, but on that SO link I provided there were many alternative suggestions to try.. I only chose recycle one as it seemed the easiest to implement.. if it still a problem may be post another question with new error you are getting.. – estinamir Mar 02 '19 at 03:01
  • Thanks - I'll do some exploring - and post another Q. if still problem. – wrcstewart Mar 02 '19 at 09:59

0 Answers0