I tried this simple JavaScript code:
eval('{"Topics":["toto","tata","titi"]}')
In the Chrome console, for example, this returns
SyntaxError: Unexpected token :
I tried the JSON on JSONLint and it's valid.
Do you see the bug?
I tried this simple JavaScript code:
eval('{"Topics":["toto","tata","titi"]}')
In the Chrome console, for example, this returns
SyntaxError: Unexpected token :
I tried the JSON on JSONLint and it's valid.
Do you see the bug?
Because eval
does not force an expression context and the string provided is an invalid JavaScript program, thus the first three tokens (and how they are looked at) are:
{ // <-- beginning of a block, and NOT an Object literal
"Topics" // <-- string value, okay (note this is NOT a label)
: // <-- huh? expecting ";" or "}" or an operator, etc.
Happy coding.