Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

empty array in JSON`

Valorous Hero ,
Oct 29, 2018 Oct 29, 2018

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.

998
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 29, 2018 Oct 29, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 30, 2018 Oct 30, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 01, 2018 Nov 01, 2018
LATEST

Hi,

try with escape() function..

evalScript("myFunc('" + escape(JSON.stringify(myArg))+ "')")

and use unescape() in jsx

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines