empty array in JSON`
Copy link to clipboard
Copied
I experienced something which I am wondering if anyone else had as well: when passed as evalScript argument, a JSON object containing an empty array is causing the error "Unterminated string constant at Line 1".
I have my evalScript statement with the syntax : evalScript("myFunc('" + JSON.stringify(myArg) + "')");
While I'm expecting it to work when the object myArg has an empty array among its properties, it throws the above-mentioned error.
Is this normal?
I'm okay with just changing an empty array to null and writing statements to watch for that in those situations where an array is expected. But hopefully it's just something I'm messing up.
Copy link to clipboard
Copied
Why don't you log or at least alert the output of the script?
myScript = "myFunc('" + JSON.stringify(myArg) + "')";
alert(myScript)
evalScript(alert)
You're see exactly what's going on then.
If that doesn't help then you can use try catch
Copy link to clipboard
Copied
It apparently made an empty array have a return line between the brackets when I did something which may have involved parsing a previously-stringified JSON object which I stored inside of an artwork's notes in Illustrator.
Copy link to clipboard
Copied
Hi,
try with escape() function..
evalScript("myFunc('" + escape(JSON.stringify(myArg))+ "')")
and use unescape() in jsx

