Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eval() = Unexpected token : error

Tags:

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?

like image 798
Tuizi Avatar asked Nov 02 '11 18:11

Tuizi


1 Answers

You have to write like this

eval('('+stringJson+')' );

to convert an string to Object

Hope I help!

like image 192
Martin Varta Avatar answered Sep 20 '22 07:09

Martin Varta