javascript - cannot access json object property returns undefined -


i accessing key json object returns undefined

{"body":"hi","date":"2016-07-29 07:43:00"}  var = json.parse(json.stringify(r.txt)); console.log(a.body)  //undefined 

value of r is

{   username: '1',   txt: '{"body":"hi","date":"2016-07-29 07:43:00"}',  } 

i have tried using stringify , parse json still return undefined.

you've parse json this. ensure whatever input you're giving json.parse, should string.

you can run below snippet ensure it's working , giving output hi.

var json = '{"body":"hi","date":"2016-07-29 07:43:00"}';    var = json.parse(json);  document.write(a.body);


Comments