Was trying to send some static data to websocket and receive the same. The data is
var details=
[
{
"_id": "5799fac61ee480492224071a",
"index": 0,
"age": 25,
"name": "Jean Pierce",
"gender": "female",
"email": "jeanpierce@cincyr.com"
},
{
"_id": "5799fac678aae9a71af63ef2",
"index": 1,
"age": 23,
"name": "Laurie Lopez",
"gender": "female",
"email": "laurielopez@cincyr.com"
},
{
"_id": "5799fac6c237d929693c08d7",
"index": 2,
"age": 21,
"name": "Padilla Barrett",
"gender": "male",
"email": "padillabarrett@cincyr.com"
}
];
When the above data is received, it is in the form of string, so I parsed it to JSON using JSON.parse(data)
and store it in the local variable. Now, the issue here is, for parsing, it need to be converted to [Object,Object]
form instead of [object Object],[object Object]
which is coming on the console. How to achieve this ?
Update: The code for the same is as below, please have a check.
Sending data to websocket server using the below code
if (client.readyState === client.OPEN) {
client.send(JSON.stringify(details));
}
On the receiving end the data is received as -
client.onmessage = function(e) {
console.log(" Fetched data :"+JSON.parse(e.data));
this.setState({ val: JSON.parse(e.data)
});
}.bind(this);
the console.log()
in the second statement is showing the result as [object Object],[object Object]
but for parsing the same in react [ Object Object]
is needed. How to achieve this ?