I am trying to parse JSON that looks like this:
{ "values" : [{ "alpha":8 },{ "beta":4 },{ "gamma":-3 } ]}
I'm parsing it with: console.log(msg.values.alpha), and get:
Missing error handler on `socket`.
TypeError: Cannot read property 'alpha' of undefined
This is how I have seen done it on other sites. Doing it with console.log(msg.values) returns undefined, and just running console.log(msg) returns proper JSON. I have seen other people with this issue, but nothing that is said to do is working. Thanks!
JSON.parse(msg)?data = JSON.parse(msg)will parse it into an object. Then you will have to follow what t3dodson said in his answer.data = JSON.parse(msg); console.log(data.values[0].alpha);?