I tried this simple JavaScript code:
eval(\'{\"Topics\":[\"toto\",\"tata\",\"titi\"]}\')
In the Chrome console, for example, this returns
USE:
function evalJson(jsArray){ eval("function x(){ return "+ jsArray +"; }"); return x(); }
var yourJson =evalJson('{"Topics":["toto","tata","titi"]}');
console.log(yourJson.Topics[1]); // print 'tata''
Number one: Do not use eval.
Number two. Only use eval to make something, well be evaluated. Like for example:
eval('var topics = {"Topics":["toto","tata","titi"]}');
Because that's evaluating an object. eval() requires you to pass in syntactically valid javascript, and all you're doing is passing in a bare object. The call should be more like:
eval('var x = {"Topics":etc...}');
FWIW, use JSON.parse instead. Safer than eval
.
if you want to make an array use the below code
var jsonObject = eval('(' +"["+ response + "]"+')');
You have to write like this
eval('('+stingJson+')' );
to convert an string to Object
Hope I help!