0

我从 URL 得到的数据格式是这样的:

#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}
]

笔记:

  1. 删除开始的字符串#RES#
  2. 删除字段"unit"

谢谢。

4

1 回答 1

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);
于 2012-06-29T20:27:06.873 回答