-1

Probably a stupid issue, but I am stuck.

I have a node.js server that sends data to a client, like this:

var message_to_client = result;
socket.send(JSON.stringify(message_to_client));

Client succesfully receives the data; if I log it on console, it reads like this:

[{"_id":"55e60d3de4b06ef3ed5f189e","par1":54.2441033, "par2":-10.177503399999999}]

I want to show the par1 value on screen, however I don't seem to be able to 'extract' it from the JSON response.

I tried with the parseJSON function from jQuery and with https://stackoverflow.com/a/22628619/3849735, neither worked.

Anyone can help? Thanks.

1
  • What do you mean by neither worked ? What are the errors you are getting ? Commented Sep 7, 2015 at 17:09

1 Answer 1

1

Send the response in json format instead in string, like

var message_to_client = result;
socket.send(message_to_client);

client side

 data[0].par1 

will return the values

Sign up to request clarification or add additional context in comments.

2 Comments

Done that, printing data gives me Object object, printing data.par1 gives undefined
client side data[0].par1 will return values

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.