【发布时间】:2013-09-25 01:58:20
【问题描述】:
我正在使用 NodeJS,以下 JSON.parse 失败,但我不知道原因:
> s[0]
'[["hands[0].session.buyin", "332"]]'
> JSON.parse(s[0]);
SyntaxError: Unexpected token
at Object.parse (native)
at repl:1:6
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at
相关字符串已从文件加载。如果我将字符串复制到控制台中它可以工作,所以我怀疑它可能与文件的编码方式有关,但我无法弄清楚是什么。 JSON.parse 的错误消息显然没有帮助。
【问题讨论】:
-
看起来不像 JSON。
-
您可以尝试使用 JSON Lint 服务来确保您的 JSON 有效。
-
s[0]看起来像二维数组,不是吗? -
文件中的行是什么样的?可以贴一下内容吗?
-
JSON.parse('[["hands[0].session.buyin", "332"]]')按预期工作。
标签: javascript json node.js