how to parse string into json object javascript -
this question has answer here:
- converting string json object 6 answers
i'm trying parse string json:
"{'firstname':'jesper','surname':'aaberg','phone':'555-0100'}"
i'm doing so:
var strjson = "{'firstname':'jesper','surname':'aaberg','phone':'555-0100'}"; console.log(json.parse(strjson));
but error message:
vm652:1 uncaught syntaxerror: unexpected token ' in json @ position 1 @ json.parse ()
does know missing , how can solve it?
you can replace single quotes double quotes , parse it.
var str = "{'firstname':'jesper','surname':'aaberg','phone':'555-0100'}"; var o = json.parse(str.replace(/\'/g, "\"")); console.log(o)
Comments
Post a Comment