Traversing JSON object

I have the following code in an HTML file:

socket.on('message',function(data) {
          console.log('Received a message from the server!',data);
          $  ('#data').append('<br />'+data.toString('utf8'));
        });

The server at certain points sends a string or sends a JSON object to the client however when I try to use JSON syntax to access the data eg/ $ ('#data').append(data.people[0].name]) it throws an error saying people is undefined. I know the data being sent is valid. How do I get my function to understand its dealing with JSON?

newest questions tagged jquery – Stack Overflow

About Admin