如何从节点红色的 json 中提取多个值

How to extract multiple value from a json in node red

我正在尝试从多个 JSON 数组中提取多个值来创建饼图。

下面的函数只能获取一个值,但我想要的是从这些数组中获取所有值,例如,标签应该 return "untagged","HK_Online"," HK_Order/Change 地址”,但目前只有 return “HK_Online”。

我的函数节点

var value = msg.payload.lines[0][1].value;
var tag = msg.payload.lines[1][0].value;

msg.topic = tag;
msg.payload = value;
return msg;

JSON数据

{
  "axes": {
    "x": [
      { "name": "Tag","type": "string" },
      { "name": "Total","type": "number" },
      { "name": "Percentage","type": "percent" },
      { "name": "Delta", "type": "delta" }
    ]
  },
  "lines": [
    [
      { "type": "string","value": "Untagged" },
      { "type": "number","value": 1 },
      { "type": "percent","value": 20 },
      { "type": "delta", "value": 100 }
    ],
    [
      { "type": "string","value": "HK_Online" },
      { "type": "number","value": 4 },
      { "type": "percent","value": 80 },
      { "type": "delta","value": 100 }
    ],
    [
      { "type": "string","value": "HK_Order/Change address" },
      { "type": "number","value": 1 },
      { "type": "percent","value": 20 },
      { "type": "delta","value": 100 }
    ]
  ]
}

您可以使用 map 方法从 lines 数组创建新数组

let lines = msg.payload.lines

let tag = lines.map(item => item[0].value)
let value = lines.map(item => item[1].value)