我从网址获取的数据格式采用以下格式:
#RES#[{"status":"Stopped \/ Idle","val":17.469444444444,"unit":"617-0003"},{"status":"Working","val":0,"unit":"617-0003"},{"status":"Headland Turning","val":0,"unit":"617-0003"},{"status":"Transport","val":0.15333333333333,"unit":"617-0003"}]
我想将其重新格式化为:
[
{
"status": "Stopped \/ Idle",
"val": 17.469444444444},
{
"status": "Working",
"val": 0},
{
"status": "Headland Turning",
"val": 0},
{
"status": "Transport",
"val": 0.15333333333333}
]
注意:
#RES#
"unit"
感谢。
答案 0 :(得分:0)
var str = '#RES#[{"status":"Stopped \/ Idle","val":17.469444444444,"unit":"617-0003"},{"status":"Working","val":0,"unit":"617-0003"},{"status":"Headland Turning","val":0,"unit":"617-0003"},{"status":"Transport","val":0.15333333333333,"unit":"617-0003"}]';
str = str.slice(5);
var json = JSON.parse(str);
console.log(json);
for (var i = 0; i < json.length; i++) {
delete json[i].unit;
}
console.log(json);