Eval() = Unexpected token : error
You have to write like this
eval('('+stringJson+')' );
to convert an string to Object
Hope I help!
FWIW, use JSON.parse
instead. Safer than eval
.
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.