gpt4 book ai didi

javascript - MySQL 在 Sequelize 5 中返回 STRING 而不是 JSON

转载 作者:行者123 更新时间:2023-12-03 22:34:35 24 4
gpt4 key购买 nike

当我向服务器发出请求时,MySQL 返回一个 STRING 对象而不是 JSON。
这是模型实例

const Task = sequelize.define(task, {
name: DataTypes.STRING,
questions: DataTypes.JSON
})

return Task
和 Controller
async index(req.res) {
try{
const id = req.params
const getTask = await task.findOne(
{
where: {id: id}
},
{ raw: true }
)

res.send(getTask)
}
catch(e) {}
}
如何获取实际的 JSON 数据而不是 STRING?谢谢

最佳答案

您没有解析结果数据。

async index(req,res) {
try{
const id = req.params
const getTask = await task.findOne({
where: {
id: id,
},
})
console.log(getTask)
}
catch(e) {}
}

关于javascript - MySQL 在 Sequelize 5 中返回 STRING 而不是 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62631276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com