adamvr/MQTT.js — Issue #6: client subscription - JSON as payload received
Author: franklovecchio
Created: 2012-02-02 05:25:58+00:00
State: open

This is the JSON I receive as a payload:

```
{
"keyone":"value",
"keytwo":"value"
}

```

Now, I try and parse the JSON (all failed attempts):

```
client.on('publish', function (packet) {
console.log('Received: ' + new String(packet.payload)); // OK

var json = JSON.parse(JSON.stringify(packet.payload));
console.log('key1: ' + json.keyone)' // undefined
});
```

```
client.on('publish', function (packet) {
console.log('Received: ' + new String(packet.payload)); // OK

var json = JSON.parse(packet.payload);
console.log('key1: ' + json.keyone)' // undefined
});
```

```
client.on('publish', function (packet) {
console.log('Received: ' + new String(packet.payload)); // OK

var json = JSON.parse(packet.payload.toString());
console.log('key1: ' + json.keyone)' // undefined
});
```

Not sure what I'm doing wrong here, but when I subscribe on a topic and the client receives any JSON string as the payload (I've validated the JSON that prints out), I can't seem to figure out what the hell I'm given back. I've tried multiple ways of doing this (see above) but nothing seems to work. What am I missing?! Please help :)