a = "{'sentiments': [['1485925200000', '0.0636363636364']]}" // typeof(a) returns string trying convert string json object in angular using json.parse(a). however, getting error.
syntaxerror: unexpected token ' in json @ position 1 @ json.parse (<anonymous>)
since have ' not supported json format, can like:
a = "{'sentiments': [['1485925200000', '0.0636363636364']]}" json.parse(a.replace(/'/g,'"')) this uses regular expressions find instances of ' , replace them ". json can parsed.
edit
a more dangerous, yet acceptable approach used in example using eval() since ' considered valid string declarator in javascript, do:
const myobject = eval(a)
Comments
Post a Comment