Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我可以将字符串中的数组转换为数组吗?Java脚本_Javascript_Arrays - Fatal编程技术网

Javascript 我可以将字符串中的数组转换为数组吗?Java脚本

Javascript 我可以将字符串中的数组转换为数组吗?Java脚本,javascript,arrays,Javascript,Arrays,我有如下数组 '[{"stuff_width":200,"_id":"cPEzHYNLHhyHbtK9MJ7F","stuff_weight":400,"stuff_length":100,"image":["cPEzHYNLHhyHbtK9MJ7F_0","cPEzHYNLHhyHbtK9MJ7F_1"],"quantity":5,"stuff_type":"Cunstruction Material \\/ Cement","stuff_height":300},{"stuff_width"

我有如下数组

'[{"stuff_width":200,"_id":"cPEzHYNLHhyHbtK9MJ7F","stuff_weight":400,"stuff_length":100,"image":["cPEzHYNLHhyHbtK9MJ7F_0","cPEzHYNLHhyHbtK9MJ7F_1"],"quantity":5,"stuff_type":"Cunstruction Material \\/ Cement","stuff_height":300},{"stuff_width":200,"_id":"F5OhdfGnoHpffkpR82KK","stuff_weight":300,"stuff_length":400,"image":["F5OhdfGnoHpffkpR82KK_0"],"quantity":5,"stuff_type":"Furniture \\/ Wood Items","stuff_height":400}]'
{"stuff_width":2,"_id":"ubcpQhAmIiGPyrqm7OpT","stuff_weight":12,"stuff_length":1,"image":["ubcpQhAmIiGPyrqm7OpT_0","ubcpQhAmIiGPyrqm7OpT_1"],"quantity":1,"stuff_type":"Cunstruction Material \/ Cement","stuff_height":12}
我可以删除第一个和最后一个单引号并将其用作简单数组吗

我用过类似的东西

courier_items.slice(1, -1);
但它给我的结果如下

'[{"stuff_width":200,"_id":"cPEzHYNLHhyHbtK9MJ7F","stuff_weight":400,"stuff_length":100,"image":["cPEzHYNLHhyHbtK9MJ7F_0","cPEzHYNLHhyHbtK9MJ7F_1"],"quantity":5,"stuff_type":"Cunstruction Material \\/ Cement","stuff_height":300},{"stuff_width":200,"_id":"F5OhdfGnoHpffkpR82KK","stuff_weight":300,"stuff_length":400,"image":["F5OhdfGnoHpffkpR82KK_0"],"quantity":5,"stuff_type":"Furniture \\/ Wood Items","stuff_height":400}]'
{"stuff_width":2,"_id":"ubcpQhAmIiGPyrqm7OpT","stuff_weight":12,"stuff_length":1,"image":["ubcpQhAmIiGPyrqm7OpT_0","ubcpQhAmIiGPyrqm7OpT_1"],"quantity":1,"stuff_type":"Cunstruction Material \/ Cement","stuff_height":12}
它的行为仍然像字符串


我希望数组不仅仅是对象

使用
JSON.parse
而不是
slice()
,因为
JSON.parse
将解析JSON数组,并将其作为数组输出:

var str='[{“材料宽度”:200,“\u id”:“材料重量”:400,“材料长度”:100,“图像”:[“材料宽度”:100,“\u0”,“材料重量”:5,“材料类型”:“结构材料\\/水泥”,“材料高度”:300},“材料宽度”:200,“\uid”:“材料重量”:300,“\u400”;“材料长度”:400“\u400”:[“F5OhdfGnoHpffkpR82KK_0”],“数量”:5,“材料类型”:“家具\\/木制品”,“材料高度:400}];
var res=JSON.parse(str);

console.log(res);
使用
JSON.parse
而不是
slice()
,因为
JSON.parse
将解析JSON数组并作为数组提供输出:

var str='[{“材料宽度”:200,“\u id”:“材料重量”:400,“材料长度”:100,“图像”:[“材料宽度”:100,“\u0”,“材料重量”:5,“材料类型”:“建筑材料\\/水泥”,“材料高度”:300},“材料宽度”:200,“\uid”:“材料重量”:300,“\u400,”:“材料长度”[\u400]:F5OhdfGnoHpffkpR82KK_0“],“数量”:5,“材料类型”:“家具\\/木制品”,“材料高度:400}];
var res=JSON.parse(str);

console.log(res);
@ForamSojitra很乐意帮忙you@ForamSojitra很高兴帮助你