javascript - JSON.parse failing without reason -


i using nodejs, , following json.parse failing cant work out why:

> s[0] '[["hands[0].session.buyin", "332"]]' > json.parse(s[0]); syntaxerror: unexpected token      @ object.parse (native)     @ repl:1:6     @ replserver.self.eval (repl.js:110:21)     @ repl.js:249:20     @ replserver.self.eval (repl.js:122:7)     @ interface.<anonymous> (repl.js:239:12)     @ interface.eventemitter.emit (events.js:95:17)     @ interface._online (readline.js:202:10)     @ interface._line (readline.js:531:8)     @  

the string in question has been loaded file. if copy past string console works, suspicion might way file encoded, cant work out what. json.parse's error messages distinctly unhelpful.

it seem string includes byte-order mark.

> s[0].charcodeat(0).tostring(16) 'feff' 

you'll have strip that out before json.parse() can manage rest.

> json.parse(s[0].trim()) [ [ 'hands[0].session.buyin', '332' ] ] 

Comments

Popular posts from this blog

mongodb - Struggling to get ordered results from the last retrieved article, given array of elements to search in -

c# - Pausing a storyboard on TabItem mouse over -

c# - Attribute value in root node of xml Linq to XML -