1function isJson(str) {
2 try {
3 let value = JSON.parse(str);
4 return value
5 } catch (e) {
6 return str;
7 }
8}
9
1var jsonPerson = '{"first_name":"billy", "age":23}';
2var personObject = JSON.parse(jsonPerson); //parse json string into JS object
1 var str = '[{"UserName":"xxx","Rolename":"yyy"}]'; // your response in a string
2 var parsed = JSON.parse(str); // an *array* that contains the user
3 var user = parsed[0]; // a simple user
4 console.log(user.UserName); // you'll get xxx
5 console.log(user.Rolename); // you'll get yyy