为什么JSON.parse('{"key":"value"}')做得很好,但JSON.parse('{key:"value"}')不行?

Joã*_*imo 1 javascript json node.js

从节点REPL:

> JSON.parse('{"key" : "value"}')
{ key: 'value' }
> JSON.parse('{key : "value"}')
SyntaxError: Unexpected token ILLEGAL
    at Object.parse (native)
    at [object Context]:1:6
    at Interface.<anonymous> (repl.js:171:22)
        at Interface.emit (events.js:64:17)
    at Interface._onLine (readline.js:153:10)
    at Interface._line (readline.js:408:8)
    at Interface._ttyWrite (readline.js:585:14)
    at ReadStream.<anonymous> (readline.js:73:12)
    at ReadStream.emit (events.js:81:20)
    at ReadStream._emitKey (tty_posix.js:307:10)
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 14

JSON中的所有键都是字符串,所有字符串都用双引号分隔.

JavaScript允许您使用不同的字符来分隔字符串,它允许您使用标识符作为对象文字中的键 - 但JSON不是JavaScript.