admin管理员组文章数量:1289558
From the node 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)
From the node 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)
Share
Improve this question
asked Aug 11, 2011 at 13:46
João Pinto JerónimoJoão Pinto Jerónimo
9,86420 gold badges64 silver badges87 bronze badges
3 Answers
Reset to default 14All keys in JSON are strings, and all strings are delimited by double quotes.
JavaScript allows you to use different characters to delimit strings, and it allows you to use identifiers as keys in an object literal — but JSON is not JavaScript.
JSON expects both keys and values to be strings.
http://www.json/js.html
Because your second example isn't JSON.
本文标签:
版权声明:本文标题:javascript - Why does JSON.parse('{"key" : "value"}') do just fine but JSON. 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741400897a2376660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论