接口获取到的数据格式:
请问怎么转换成数组:
//以下是想要的结果:
[
pubID: "220414",
source: "device",
attrib:[{d: "4", x: "0", y: "2", w: "160", h: "32"}],
cmd:[{end: "1650069045",fontsize: "12",num: "2",speed: "4",start: "1650068789",style: "1"}],
pages: ["||PM2.5 ug/m3PM10 ug/m3||"],
["||TSP ug/m3噪声 dB||"]
]
let array = [] array.push(res)
let arr = []
for (let key in res) {
arr[0][key] = key === "pages" ? res[key] : [res[key]]
}
//数组结构 list:{ pubID: "220414", source: "device", attrib:{a: "4",b: "32",c: "160",d: "0",e: "2"}, cmd:{g: "12",h: "14",i: "18",j: "1",k: "5"}, pages:[ ["||PM2.5 ug/m3PM10 ug/m3||"], ["||TSP ug/m3噪声 dB||"] ] } //数据实现 list:[ pubID: "220414", source: "device", attrib:[{a: "4",b: "32",c: "160",d: "0",e: "2"}], cmd:[{g: "12",h: "14",i: "18",j: "1",k: "5"}], pages:[ ["||PM2.5 ug/m3PM10 ug/m3||"], ["||TSP ug/m3噪声 dB||"] ] ]