json - Express.js:如何在 JSON 中使用模板文字?
问题描述
我在一个名为 db.json 的文件中有这个 JSON 对象:
"lyrics": "Am9 Keep you in the dark F#m7(b5) F7M You know they all pretend Am9 Keep you in the dark F#m7(b5) F7M And so it all began"
以及 js 文件中的这段代码:
exports.addLyrics = (req, res, next) => {
const lyric = req.body;
db.get('lyrics').push(lyric).last().assign({
id: Date.now().toString()
}).write();
res.status(200).send(lyric);
};
我正在使用邮递员,想用模板文字发布歌词,这样我就可以在正确的位置传递歌词和弦,如下所示:
"lyrics": `
Am9
Keep you in the dark
F#m7(b5) F7M
You know they all pretend
Am9
Keep you in the dark
F#m7(b5) F7M
And so it all began`
问题:在这种情况下,如何将模板文字存储和加载为 JSON?
解决方案
推荐阅读
- git - Azure 存储库的备份
- python - python从文件中形成一个字典
- image - 微观策略:加载动态图像
- ansible - 通过 Ansible 修改 PATH 变量
- function - 为什么这个 micropython 函数不起作用?
- python - 链接的 for 循环不会增加计数器的值
- php - 无法为 DateRangePicker::widget 设置占位符
- jsf - 带有 ExtensionlessURLs / Omnifaces 的 JSF
- html - 如何从顶部为下降的 div 设置动画并旋转?
- reactjs - react-data-grid中的行更新后如何删除排序箭头?