I have a string object which is as follows:-
[{"TradeId":123423,"TradeDate":"2017-12-11T18:30:00.000Z","Commodity":"AL","Side":"Buy","Qty":100,"Price":2000,"Location":"NY"},
{"TradeId":123428,"TradeDate":"2017-12-15T18:30:00.000Z","Commodity":"AL","Side":"Buy","Qty":100,"Price":2000,"Location":"NY"}]
I want to use this as an array on which map can be invoked. How can this be achieved.
I did JSON.parse() of this string, but I get an error stating the following:-
Unexpected token o in JSON at position 1
When I do
JSON.parse('[{"TradeId":123423,"TradeDate":"2017-12-11T18:30:00.000Z","Commodity":"AL","Side":"Buy","Qty":100,"Price":2000,"Location":"NY"},
{"TradeId":123428,"TradeDate":"2017-12-15T18:30:00.000Z","Commodity":"AL","Side":"Buy","Qty":100,"Price":2000,"Location":"NY"}]')
note the quotes ('') , from my node terminal, it works!!!
please note that I get this string from a websocket.
My end goal is to use this string as an Array on which I can use the map operation
socket.on('getdata', (msg) => {
console.log("getdata",msg);
//TradesActions.loadTrades(msg)
myStore.dispatch(TradesActions.loadTrades(JSON.parse(msg.toString())))
})
After it is dispatched above(react+redux), its used is some component as follows:-
trades.map((trade, index) => {...})
Thanks, Amar
JSON.parse([{}]).