John Jameson
John Jameson

Reputation: 53

Socketio Unexpected end of input

I have a question related to SocketIO, NodeJS and javascript. I have a client, which should show information in realtime. I'm using this code to parse JSON object

socket.on('message', function(dataString){
        var data=JSON.parse(dataString.replace(/'/g, '"'));
        //..Extra stuff to process the data
}

However I got Uncaught SyntaxError: Unexpected end of input, everytime that the message arrives to the client.

What can I do to avoid this error?

Cheers

Upvotes: 0

Views: 339

Answers (1)

Mike Roberts
Mike Roberts

Reputation: 161

You seem to be missing a ')', try this:

socket.on('message', function(dataString){
        var data=JSON.parse(dataString.replace(/'/g, '"'));
        //..Extra stuff to process the data
});

Upvotes: 1

Related Questions