I have N txt files with each row of data and how many fields each line has. Can NodeJS read this file and get json formatted data?
ask for advice on how to use api to implement, or give a small demo thank you, online urgent wait
I have N txt files with each row of data and how many fields each line has. Can NodeJS read this file and get json formatted data?
ask for advice on how to use api to implement, or give a small demo thank you, online urgent wait
this kind of random search is a lot of information. What is there to ask for advice?
introduce fs
into fs
. Json can directly use the string read JSON.parse
. If it is not a standard JSON, it is nothing more than a string cutting function split
or regular cutting and assembling
const fs = require('fs');
const path = 'd:/node/demo.txt';
const str = fs.readFileSync(path).toString();
console.log(str);
console.log(JSON.parse(str));
1. Node can read the contents of a file. You can refer to Node official document-File Operation
2. Formatting the file content as JSON, depends on the format of your data, how the key:value is divided, and how each key is divided. You can use regular matching to get
Previous: Weex in-depth learning
Next: Who can tell me why the, koa request server forwards why the front-end access is a 404?
< H2 > question 1 < H2 > I want to write an interface to update user information, UPDATE user_information SET the parameters here are not fixed where uid =? could be name=? or name=?, sex=? or name=?, sex=?, qq=? Please how should I achi...