【发布时间】:2019-05-03 20:13:28
【问题描述】:
调用 JSON stringify 时出现循环引用异常,但找不到循环引用。看来 jQuery 是这里的罪魁祸首,但我没有看到问题,也无法进入 JSON 字符串化。
const list = $('.use-in-reporting-checkbox:checkbox:checked').map(function()
{
return this.value;
});
const dataPacket = {
datasetIDs: list
};
try {
const real = JSON.stringify(dataPacket);
} catch (error) {
processError(error);
}
"Error reports: Converting circular structure to JSON
--> starting at object with constructor 'Object'
property 'selectorData' -> object with constructor 'Object'
| property 'elements' -> object with constructor 'Array'
--- index 0 closes the circle"
But, inspection of dataPacket just shows: "datasetIDs init (37)" with the
list of checkbox values. Not sure how to debug this.
【问题讨论】:
标签: jquery arrays json ecmascript-5