0

I'm getting an 'Uncaught SyntaxError' while trying to parse a JSON string, and I can't figure out why.

It looks like message is a string, which seems to be a common problem, and the json appears to be valid. A snippet of my code is given. It fails on the var obj = ... line.

this.send = function (message) {
    console.log(message);
    console.log(message.toString());
    console.log('{"ReadyToGo":1}');
    console.log(typeof message);
    var obj = $.parseJSON(message);
}

On the console, I get this just before the error.:

{"ReadyToGo":1}
{"ReadyToGo":1}
{"ReadyToGo":1}
string

Any ideas?

EDIT: Added console.log(typeof message), which yields 'string'

His Royal Redness
  • 721
  • 1
  • 9
  • 17

1 Answers1

0

OK, I got this sorted. A null character ( '\0' ) was been appended to the string somewhere along the long call chain, and this wasn't visible in the debugger. Thanks to cookie monster for the heads-up on this one.

Everything works as soon as I strip out the null char.

His Royal Redness
  • 721
  • 1
  • 9
  • 17