gpt4 book ai didi

javascript - 为什么我在运行 mysql 查询时在 Node JS 中收到 'Converting circular structure to JSON' 错误?

转载 作者:行者123 更新时间:2023-11-29 15:46:20 24 4
gpt4 key购买 nike

我正在做一个 mysql 查询来选择表中的所有数据(名称 LOGIN)和

https://localhost:2000/select and the params to be passed in the req.body is the table_name value is login and when i hit the api using postman, it returns an empty set with consolelog says,

TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at Object.selecting (/home/andiswamy/Documents/fuDDie/shayam/dbConnection.js:67:23)
at process._tickCallback (internal/process/next_tick.js:68:7)

我的代码是:

router.get('/select', async (req, res) =>
{
let table_name = req.headers.table_name;
try {
let inserting = await db.selecting(table_name);
console.log(inserting);

res.send(stringify(inserting));
res.end();
} catch(err) {
console.log(err);
}
});

async function selecting(table_name) {
try {
let result = await testDB.query(`SELECT * FROM ${table_name}`);
console.log(typeof result);
result = JSON.stringify(result);
return result;
} catch (e) {
return e;
}
}

最佳答案

let room = {
number: 23
};

let meetup = {
title: "Conference",
participants: ["john", "ann"]
};

meetup.place = room; // meetup references room
room.occupiedBy = meetup; // room references meetup

JSON.stringify(meetup); // Error: Converting circular structure to JSON

请参阅上面的示例,当您将两个对象相互引用并尝试将它们字符串化时,就会发生此错误。

关于javascript - 为什么我在运行 mysql 查询时在 Node JS 中收到 'Converting circular structure to JSON' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56986694/

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