javascript - JSON.parse — "unexpected token"构造的 JSON 字符串

标签 javascript json parsing syntax token

这会抛出:“未捕获的语法错误:意外的标记 n(…)” ...

var text = "notation: 'fixed', precision: 2";
JSON.parse("{" + text + "}");

没有关于为什么或如何安全解析的线索。

最佳答案

你应该试过a linter首先。

问题是您在 text 中对键/值使用了单引号,或者根本没有使用。

您的文本应该是:

var text = '"notation": "fixed", "precision": "2"';

关于javascript - JSON.parse — "unexpected token"构造的 JSON 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33973982/

相关文章:

javascript - HTML如何使水平条标签居中?

javascript - 将包含对象数组的 javascript 对象格式化为数组数组

python - 如何解析没有明确分隔符的txt.文件

javascript - 使用 jQuery 在选择框选项更改时更改输入框占位符

javascript - Google Trusted Stores Test Drive 未在 IE11 中显示

javascript - 将纯 Nativescript 5.x 项目迁移到 Nativescript 6 - JS ERROR NOT READY : generator isn't seeded

python - 元素包含未转义双引号的 JSON 字符串

javascript - 在 Nodejs 中以 GraphQL 类型分配 JSON

c++ - linux守护进程的结构

json - 在Swift 3中正确解析JSON