I don't know about JavaScript, but I need to use just a little part of it. I have a url "http://my-url/api/auth/v1" that generates me the following json response:
{
"token": {
"token": "token-result-here",
"result": null,
"resultCode": "0",
"requestId": "xx"
},
I need a script that returns me just the result of "token". For example, when I call "token", it returns: "token-result-here". Could anyone help me with this code?
CodePudding user response:
If
var response = {
"token": {
"token": "token-result-here",
"result": null,
"resultCode": "0",
"requestId": "xx"
}};
then use response.token.token
to access "token-result-here"
CodePudding user response:
You can save the request to the api to a variable let's say "apiResponse" and you can do this:
//parse the JSON
JSON.parse(apiResponse);
//access the JSON
let token = apiResponse.token.token;