if json then parse
var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson); //parse json string into JS objectfunction isJson(str) {
try {
let value = JSON.parse(str);
return value
} catch (e) {
return str;
}
}
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
Also in JavaScript:
- laravel variable in javascript
- summernote mentions ajax
- jquery OR operation
- mongodb replace document
- javascript class constructor
- jquery get id of 3rd parent
- multiple conditions for JavaScript .includes() method
- owl carousel json not working
- basic javascript
- call laravel route js
- javascript file preview
- jquery table each rows with class
- hamburger menu html and css
- creating js objects
- urlencode jquery
- give spacing in flutter
- js set visibility on timeout
- jquery clear file input
- c# loop through json
- check if value is a string javascript
- javascript import
- get json data when we get error code in axios
- toggle switch angularjs
- react navigation 4