I am passing valid JSON on the server side (using node.js) but not able to parse on the client side (using jQuery). jQuery.parseJSON returns null. Any assistance will be much appreciated.
Server side-
var message = [{key:"1", count:1},{key:"2", count:2}];
client.publish('update', JSON.stringify(message));
Client side -
socket.on("update", function(data) {
var obj = jQuery.parseJSON(data);
alert (obj); // returns null
// do something
}
databeing received?JSON.parsetakes a string, so there's the problem. If you're on Chrome (or Firefox with Firebug), useconsole.log(data)instead ofalertthen press F12 to inspect the object properties. Either your JSON string is inside a property of thedataobject ordatais the parsed object already.