Javascript how to convert json string to dynamic object
Answers
Answered by
0
Zvzgayayv z s wys xudbd
Answered by
0
Hi
JSON.parse() is used to convert json into an Object
// Here we have stored sample json data in `userJson` variable
var userJson = '{"name": "Ajay"}';
// Here we are coverting that json into an object
// with the help of JSON.parse()
var userObj = JSON.parse(userJson);
// And here we are trying to fetch username from `userObj`
console.log(userObj.name);
// expected output: Ajay
Attachments:
Similar questions