在将string转换为对象时获取syntaxError意外的令牌

我想转换提供的对象数组中的string

var string = "[{cpu:100,memory:47,freeDisk:83,networks:[{name: \"ctm-4680b9b244c\", status : \"active\"},{name: \"ctm-c2f21106323\", status : \"active\"},{name: \"ctz-1977174d443\", status : \"active\"},{name: \"ctz-1b49d8ccfa5\", status : \"active\"},{name: \"ctz-28c7ceda9ce\", status : \"active\"},{name: \"ctz-3337b7f252a\", status : \"active\"},{name: \"ctz-bbe9792d0c7\", status : \"active\"},{name: \"ctz-d400e32307d\", status : \"active\"},{name: \"ens33\", status : \"active\"},{name: \"lo\", status : \"active\"},{name: \"ctz-9bf91c248f9\", status : \"inactive\"}],infrastructurename:\"ct-colormaster-host\", infrastructurestatus:\"running\", infrastructureuptime: \"Sat Aug 12 00:00:00 UTC 2017\", infrastructureuptimeSince:{ days: 0, hours: 3, minutes: 39},infrastructuredowntime:', infrastructuredowntimeSince:{days: 0, hours: 0, minutes: 0}, infrastructurecurrentCheckTime : \"Sat Aug 12 06:23:25 UTC 2017\"}]" 

我需要把它转换成

 [ { cpu:100, memory: 47, freeDisk: 83, networks: [ { name: "ctm-4680b9b244c", status: "active" }, { name: "ctm-c2f21106323", status: "active" }, ... ] } ] 

我试图JSON.parseeval但他们都不工作,给我意想不到的令牌非法错误

请build议我如何将此string转换为对象。

如果它必须是一个string,你需要引用属性名称:

 [{ "cpu" : 100 }] 

此外,我不确定是否只是为了这个问题创build了内联string,或者如果你正在实际的代码中这样做。 如果它在你的实际代码中,你可以使用单引号来避免双引号的转义:

 var string = '[{"name": "ctm-4680b9b244c"}]'