我不知道如何使用mysql /node正确存储对象数组



我试图制作一个表,在那里我可以注册项目列表。实际上,除了阵列对象存储之外,其他一切都在工作。

我试了很多东西,我的sql上的Blob格式-但我无法用.JSON((将数据放回前面(nuxt((.JSON(无法用此方法识别(。转换缓冲区数据

我试图将其存储为JSON格式,但mysql无法识别。

现在我把它放在sql上的TEXT格式中(但当我回调数据时,我只得到[object object]-无法在前面或后面通过它。

我想储存一些类似的东西

[
{"quantity":"2","content":
{"id":21,"reference":"LEG080276","designation":"cadre saillie mozaic blanc 2x6/8 modules 2x3 postes - prof 50mm","description":"sens de montage (horizontal)  nombre de modules (12)"}
},
{"quantity":"2","content":
{"id":6,"reference":"LEG080260L","designation":"voyant 2 modules 0.03w pour support batibox 1 poste ","description":null}
}
]

这是node.js中的调用路由-列表(对象数组(应该存储在内容中

router.post('/list', function getApi(req, res) {
const {user_id, to_uuid, content, message, list_name, status}= req.body;
db.query(`INSERT INTO list (user_id, to_uuid, content, message, list_name, status) VALUES (?,?,?,?,?,?)`, [user_id, to_uuid, content, message, list_name, status], (err, results) => {
if (err) {
res.status(500).send(`Erreur lors de l'enregistrement de la liste`);
console.log(err);
}
res.status(200).send('Liste Enregistrée');
});
});

有人有主意吗?

提前感谢

所以我成功了!!!

我在mysql工作台中将对象数组(字符串化(注册为文本格式!

成功了!!

this.$axios.post('http://localhost:3000/api/list/', {
'user_id': this.$auth.user[0].user_id,
'to_uuid':  this.$store.state.list.to_user.user_id,
'content': JSON.stringify(this.$store.state.list.finalList),
'message': this.message,
'list_name': this.name,
'status': "en attente"
})

这部分是当我在内容上发布字符串化数组时

async created(){
const listReceived = await this.$axios.$get(`/api/listReceived/${this.$auth.user[0].user_id}`)
const usersList = await this.$axios.$get("/api/users")

listReceived.forEach(element => {
const userdata=usersList.filter((post)=>post.user_id===element.user_id)
const userSelected={
listId:element.list_id,
listName:element.list_name,
message:element.message,
status:element.status,
content: JSON.parse(element.content),
nickname:userdata[0].nickname
}
this.finalList.push(userSelected)
})

这部分是当我获得字符串化数组时-i JSON.在内容上分析它

最新更新