【发布时间】:2018-12-14 20:58:27
【问题描述】:
我很难弄清楚如何在某个地方写作?我想写下 ReadData.welcome_message[0] 这个命令指出的地方。
我的 database.json 文件有这个;
{"faqs":["Birkere bir?","bir"],"welcome_message": ["welcome"]}
ReadData.welcome_message[0] 表示欢迎
const fs = require('fs'); //imports node.js FileSystem
const ReadDatabase = fs.readFileSync('database.json'); //reads the file in synchronized way
const ReadData = JSON.parse(ReadDatabase); //parses bits so it can be readable
//These three for me to understand what is where
console.log(ReadData.faqs[0]);
console.log(Object.keys(ReadData));
console.log(ReadData.welcome_message[0]);
let edited_welcome = JSON.stringify(edited_message);
fs.writeFileSync('database.json', edited_welcome)//I understand this is the way to write to the file
//console.log('"' +edited_message + '"'); //did help me understand if my code worked
});
【问题讨论】:
-
不要投反对票,如果可以,请回答!我为此苦苦挣扎了几个小时并寻找答案。找不到任何可以解决我的问题的东西。我理解也许你们太优秀了,但这不是激励编码新手的方式。
-
这可能会给你一些见解可能是stackoverflow.com/questions/10685998/…
标签: javascript arrays node.js telegram-bot