如何解决NodeJs Cheerio 结果:使用 lodash 将数组数组转换为 JSON 对象?
我正在尝试从站点获取一些信息,并且希望将其更好地格式化为键和值的对象。我正在使用 nightmare 和 cheerio-tableparser 来解析一个复杂的表...目前数据在一个数组数组中,我想映射键值对。第一个数组 array[0]
和第二个数组 array[2]
是键,array[1]
和 array[3]
是值......有没有一种简单的方法可以使这种与 lodash 关联?该数组有 16 个数组,但都遵循相同的关系。但是,我想忽略 if a key is null and a value is null
。
所以,关系是:
{
"array[0][0]" : "array[1][0]","array[0][1]" : "array[1][1]"
...
}
映射到:
{
"Serial Number" : "627","Manufacturer Name" : "DEHAVILLAND"
...
}
数组
[
[
"Serial Number","Manufacturer Name","Model","Type Aircraft","Pending Number Change","Date Change Authorized","MFR Year","Type Registration","Name","Street","City","County","Country","Type Certificate Data Sheet","Engine Manufacturer","Engine Model","A/W Date","The information contained in this record should be the most current Airworthiness information available in the historical aircraft record. However,this data alone does not provide the basis\n for a determination regarding the airworthiness of an aircraft or the current aircraft configuration. For specific information,you may request a copy of the aircraft record at\n http://aircraft.faa.gov/e.gov/ND/","None","Certificate Number","None"
],[
"627","DEHAVILLAND","DHC-2 MK. I(L20A)","Fixed Wing Single-Engine","1953","Corporation","WARD AIR INC","8991 YANDUKIN DR","JUNEAU","JUNEAU DIV","UNITED STATES","NONE","12/10/1976","T061436",[
"Status","Certificate Issue Date","Expiration Date","Type Engine","Dealer","Mode S Code (base 8 / Oct)","Mode S Code (Base 16 / Hex)","Fractional Owner","State","Zip Code","Type Certificate Holder","Classification","Category","Exception Code","Issue Date",[
"Valid","02/24/2006","07/31/2022","Reciprocating","No","52022212","A8248A","NO","ALASKA","99801-8086","Standard","Normal","None"
]
]
解决方法
这是我的解决方案:
let reg1 = _.zipObject(tables[0],tables[1]);
let reg2 = _.zipObject(tables[2],tables[3]);
return {...reg1,...reg2}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。