首页 > 解决方案 > 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?

标签: jsonexpresspostmanwysiwygliterals

解决方案


推荐阅读