這裏slahses用來逃避你的JSON編碼字符串的charatcer "
(不是JSON對象,因爲
> JSON.parse("{messages:1}")
SyntaxError: Unexpected token m
at Object.parse (native)
at repl:1:7
at REPLServer.eval (repl.js:80:21)
at Interface.<anonymous> (repl.js:182:12)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)
at Interface._ttyWrite (readline.js:603:14)
at ReadStream.<anonymous> (readline.js:82:12)
at ReadStream.emit (events.js:88:20)
,因此密鑰必須與"
封閉來表示一個字符串,但你不能只是把"
裏面的字符串。爲了解決這個問題JSON解析器追加\
> JSON.parse("{\"messages\":1}")
{ messages: 1 }
所以當你分析,只需撥打會話串JSON.Parse
> JSON.parse("{\"messages\":{\"cometchat\":{\"timedifference\":0,\"cometchat_buddytime\":0,\"msgavails\":\"\"}}}")
{ messages:
{ cometchat:
{ timedifference: 0,
cometchat_buddytime: 0,
msgavails: '' } } }