0

This is the first time i am working with Web sockets please pardon any error.

I am using rxjs websockets with Angular. the data i get in the browser is something like this from the websocket

'[["lnkd",76.86839599398574],["mu",127.8241808237684],["msft",174.50062080196034],["yhoo",96.43342811472303]]'

This is data i get in console . I am not able to use ngFor on this as it is a String type data . I want to be able to get the data in form of an array or array instead of in String is this possible .

As of now i get this in broswer using {{data | async }} but i need it a table format using ngfor

INFOSYS
  • 1,465
  • 9
  • 23
  • 50

1 Answers1

1

This is a JSON string. You need to first parse it into a object using JSON.parse() as described here.

https://www.w3schools.com/js/js_json_parse.asp

var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
Jan Schmutz
  • 799
  • 3
  • 10
  • 28
  • is it a json it starts with `[` instead of `{` – INFOSYS Oct 04 '17 at 17:57
  • you have a 2 dimensional array formatted as a JSON string. Top Level Arrays are legal in JSON objects. https://stackoverflow.com/questions/3833299/can-an-array-be-top-level-json-text – Jan Schmutz Oct 04 '17 at 18:07