xxxxxxxxxx
var str = '[{"UserName":"xxx","Rolename":"yyy"}]'; // your response in a string
var parsed = JSON.parse(str); // an *array* that contains the user
var user = parsed[0]; // a simple user
console.log(user.UserName); // you'll get xxx
console.log(user.Rolename); // you'll get yyy
xxxxxxxxxx
var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson); //parse json string into JS object
xxxxxxxxxx
//JSON.parse()
const json = "{\"name\": \"Example\", \"age\": 50}";
let parsed_json = JSON.parse(json);
console.log(`Name: ${parsed_json.name}; Age: ${parsed_json.age}`)
// Returns "Name: Example; Age: 50"
xxxxxxxxxx
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
xxxxxxxxxx
const json = '{"fruit": "apple", "mango": 10}'
const json = JSON.parse(json);
console.log(obj.fruit,obj.mango)