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

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


这是模型实例


const Task = sequelize.define(task, {

  name: DataTypes.STRING,

  questions: DataTypes.JSON

})


return Task

和控制器


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?谢谢


小怪兽爱吃肉
浏览 56回答 1
1回答

收到一只叮咚

您没有解析结果数据。async index(req,res) {  try{     const id = req.params     const getTask = await task.findOne({     where: {        id: id,    },     })     console.log(getTask)  }  catch(e) {}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript