gpt4 book ai didi

javascript - 使用 eval() 在 JavaScript 中将字符串转换为 JSON 对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:07:37 24 4
gpt4 key购买 nike

<分区>

我正在将以下 JSON 变量转换为字符串。当返回 JSON 时,我收到一个错误(在 ReactJS 中,尽管它不重要)。

var questionGlobal = {
"questionCons": [{
"string": "In",
"alignment": 2
}, {
"string": "New York State",
"alignment": 1
}, {
"string": "the",
"alignment": -1
}, {
"string": "shortest",
"alignment": -1
}, {
"string": "period",
"alignment": 0
}, {
"string": "of",
"alignment": 2
}, {
"string": "daylight",
"alignment": 0
}, {
"string": "occurs",
"alignment": 2
}, {
"string": "during",
"alignment": 1
}, {
"string": "which",
"alignment": 0
}, {
"string": "month",
"alignment": 0
}],
"options": [{
"string": "January",
"alignment": 1
}, {
"string": "December",
"alignment": 2
}, {
"string": "June",
"alignment": 1
}, {
"string": "July",
"alignment": 1
}]
};

命令如下:

window.console.log( eval(JSON.stringify(questionGlobal)));

我在控制台中得到的输出是:

Uncaught SyntaxError: Unexpected token

知道我哪里做错了吗?

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