SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How do I get javascript value out of a JSON string

    Hi,
    I'm developing an app with Node.js and I have this code when I send a message to a server:
    Code:
    var msg = {
            name: userName,
            text: ABCD
     };
     var json = JSON.stringify({ type:'message', data: msg });
     socket.send(json);
    And here the code that receives the message from the server:
    Code:
    socket.addEventListener("message", function(event) {
         console.log (event.data);
    });
    Here's what it displays:
    Code:
    
    {"type":"message","data":{"name":"userName","text":"ABCD"}}
    I wonder if I can get it displayed like this:
    Code:
    userName
    ABCD
    I have taken the code from here: http://martinsikora.com/nodejs-and-w...-chat-tutorial
    I guess the author have a function that explodes the string and grab the value accordingly, but I don't understand what is that function.

    Thanks

  2. #2
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Never mind I get it worked.

    Wooh!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •