var vString = "{ "var1":"varA", "var2":"varB", "var3":"varC" }";
var literalArray = vString;
console.log(literalArray["var1"]); // = varA
如何将字符串转换为文字数组?
答案 0 :(得分:2)
修改您的代码,如下所示:
var vString = '{ "var1":"varA", "var2":"varB", "var3":"varC" }';
var literalArray = vString;
console.log(JSON.parse(literalArray)["var1"]);
答案 1 :(得分:1)
这对你有用......
var string = '{"var1":"varA", "var2":"varB", "var3":"varC" }';
var objectArray = (new Function("return " + string+ ";")());
console.log(objectArray.var1);