简体   繁体   English

如何读取 node.js 中的.dat 文件并转换为人类可读的文本/json

[英]How can I read .dat file in node.js and convert to human-readable text/json

I have a .dat file that contains information that is not clear to read it.我有一个.dat文件,其中包含阅读起来不清楚的信息。

So, I was trying to read that file and convert it to human-readable text/json.所以,我试图读取该文件并将其转换为人类可读的文本/json。

I implemented this code but don't know how to convert readable text/json file.我实现了这段代码,但不知道如何转换可读文本/json 文件。

 fs.readFile('./2.dat', 'utf8', (err, data) => {
    if (err) throw err
    console.log(data)
  })

This is the file 2.dat这是文件2.dat

Your file looks like some kinf of CSV with |你的文件看起来像 CSV 的一些亲戚| as a delimiter.作为分隔符。 YOu need to use some package to parse CSV like csv-parse to get lines as JS-objects.您需要使用一些 package 来解析 CSV,例如csv-parse以获取作为 JS 对象的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM