所以我有一个轮询器轮询设备以获得如下响应:
{"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
},
}
我需要构造对象看起来就像我提到的那样。我确信有一个简单的方法可以做到这一点。此外,如果有更好的方法,它会是什么?