【发布时间】:2020-08-26 17:26:02
【问题描述】:
我在保存和访问我的 JSON 数据时遇到问题,JSON 文件中的所有对象都被转换为 字符串,偶数。
这是我从HTML FORM 到GET 数据的快速路线
control.post('/like/:id',getuserdata, async (req, res, next) => {
try{
let likedata = './bin/like/likedata.json'
let title = res.accountuser.title;
let pass = res.accountuser.password;
let tags = req.body.likes;
let actions = req.body.action;
let like = {
username: title,
password: pass,
tag: tags,
times: actions,
}
let jsonlike = JSON.stringify(like)
fs.appendFileSync(likedata, jsonlike)
next();
res.redirect('/dashboard')
} catch (err){
console.log(err)
}
});
当我添加两次或更多次值时,我的 JSON 文件是这样出现的,JSON 文件显示错误 End of file expected.
{"username":"account1","password":"somepass1","tag":"hello","times":"5"}{"username":"account2","password":"somepass2","tag":"helllo","times":"444"}
我想单独使用这个 JSON 数据,在这里:
const ig = require('./like');
var cron = require('node-cron');
const iglike = async() => {
await ig.initialize();
await ig.login(username, password); //here
await ig.liketagsprocess(tag, times); //here
};
cron.schedule('* */4 */12 * * *', function() {
iglike();
});
module.exports = iglike;
我该怎么做?
【问题讨论】:
标签: node.js arrays json express