从 json 数据创建自定义对象数组
create custom objects array from json data
我有一个 json 对象数组,如:
[{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":10},{"SensorID":2,"Temperature":34.0,"Humidity":43.0,"Carbon":87.0,"DateTime":"2017-03-09T12:00:00","ID":12},{"SensorID":2,"Temperature":23.0,"Humidity":89.0,"Carbon":65.0,"DateTime":"2017-03-09T12:00:00","ID":13},{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":16},{"SensorID":2,"Temperature":87.0,"Humidity":34.0,"Carbon":23.0,"DateTime":"2017-03-08T10:07:00","ID":18},{"SensorID":2,"Temperature":44.0,"Humidity":67.0,"Carbon":43.0,"DateTime":"2017-03-08T10:07:00","ID":20},{"SensorID":2,"Temperature":100.0,"Humidity":100.0,"Carbon":100.0,"DateTime":"2017-03-08T10:07:00","ID":21},{"SensorID":2,"Temperature":70.0,"Humidity":20.0,"Carbon":50.0,"DateTime":"2017-03-08T10:07:00","ID":22}]
现在我想要一个像
这样的数组
[[Date.UTC(2015,1,13),0.8783],
[Date.UTC(2015,1,15),0.8774],
[Date.UTC(2015,1,16),0.8807],
[Date.UTC(2015,1,17),0.8762],
[Date.UTC(2015,1,18),0.8774],
[Date.UTC(2015,1,19),0.8798],
[Date.UTC(2015,1,20),0.8787],]]
我需要在 highstock 中使用第二个数组如何从第一个数组创建第二种格式的数组
这似乎是使用 map
的问题。基本思想是对列表中的每个元素应用一个函数,同时创建一个新列表。
xs = [{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":10} ... ]
otherArray = xs.map(function(x) {
// or whatever logic you need...
return Date(x.DateTime);
})
我有一个 json 对象数组,如:
[{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":10},{"SensorID":2,"Temperature":34.0,"Humidity":43.0,"Carbon":87.0,"DateTime":"2017-03-09T12:00:00","ID":12},{"SensorID":2,"Temperature":23.0,"Humidity":89.0,"Carbon":65.0,"DateTime":"2017-03-09T12:00:00","ID":13},{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":16},{"SensorID":2,"Temperature":87.0,"Humidity":34.0,"Carbon":23.0,"DateTime":"2017-03-08T10:07:00","ID":18},{"SensorID":2,"Temperature":44.0,"Humidity":67.0,"Carbon":43.0,"DateTime":"2017-03-08T10:07:00","ID":20},{"SensorID":2,"Temperature":100.0,"Humidity":100.0,"Carbon":100.0,"DateTime":"2017-03-08T10:07:00","ID":21},{"SensorID":2,"Temperature":70.0,"Humidity":20.0,"Carbon":50.0,"DateTime":"2017-03-08T10:07:00","ID":22}]
现在我想要一个像
这样的数组[[Date.UTC(2015,1,13),0.8783],
[Date.UTC(2015,1,15),0.8774],
[Date.UTC(2015,1,16),0.8807],
[Date.UTC(2015,1,17),0.8762],
[Date.UTC(2015,1,18),0.8774],
[Date.UTC(2015,1,19),0.8798],
[Date.UTC(2015,1,20),0.8787],]]
我需要在 highstock 中使用第二个数组如何从第一个数组创建第二种格式的数组
这似乎是使用 map
的问题。基本思想是对列表中的每个元素应用一个函数,同时创建一个新列表。
xs = [{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":10} ... ]
otherArray = xs.map(function(x) {
// or whatever logic you need...
return Date(x.DateTime);
})