0

所以我有一个轮询器来轮询设备以获取如下所示的响应:

{"mode":"41","pid":"0C","name":"rpm","value":1817.75}

我有多个具有相似响应的轮询器。说,另一个具有以下响应的轮询器:

{"mode":"41","pid":"05","name":"temp","value":81}

每次轮询以 500 毫秒的间隔进行。我需要以某种形式记录所有这些数据。

现在会发生什么?

我有一个看起来像这样的日志:

{"data": {"mode":"41","pid":"0C","name":"rpm","value":1817.75}, "time": "someTime" },
{"data": {"mode":"41","pid":"05","name":"temp","value":81}, "time": "someOtherTime" }

我想要达到什么目的?

如下所示的日志:

{ 
  "data": {
            "rpm": {"mode":"41","pid":"0C","name":"rpm","value":1817.75},
            "temp":{"mode":"41","pid":"05","name":"temp","value":81},
            "time": newTime
          },
 "data": {
            "rpm": {"mode":"41","pid":"0C","name":"rpm","value":1817.75},
            "temp":{"mode":"41","pid":"05","name":"temp","value":81},
            "time": newTime
          },
 "data": {
            "rpm": {"mode":"41","pid":"0C","name":"rpm","value":1817.75},
            "temp":{"mode":"41","pid":"05","name":"temp","value":81},
            "time": newTime
          },
}

我需要构造对象,使其看起来像我提到的那样。我确信有一个简单的方法可以做到这一点。另外,如果有更好的方法可以做到这一点,那会是什么?

4

0 回答 0