How to read a particular value from the json.stringify: ionic
How to read a particular value from the json.stringify: ionic
From the post i have got a res as
.subscribe( res =>
let result = JSON.stringify(res);
alert(result)
)
& as the response of alert(result)
I’m getting
alert(result)
"access_token": "hjhdshJHUHYI67HUjhhk98BJ_BJHBBHbnbhbhbjh_jmnhghmghgfffgxcgfcf98hujh",
"expires_in":"518399"
Here I want to read the access_token
value & save it in a variable how Can I do it?
access_token
res.access_token
should do it. I understand now what you''ve been doing– user184994
Sep 1 at 16:47
res.access_token
4 Answers
4
You dont have to stringify, just access it as res.access_token
res.access_token
.subscribe((res:any) =>
let result = res.access_token;
alert(result)
)
Property 'access_token' does not exist on type 'Object'.
– raj_tx
Sep 1 at 16:49
check the edited answer
– Sajeetharan
Sep 1 at 16:49
Just access that property of the object with the usual syntax.
.subscribe( res =>
let the_variable = res['access_token']; //or `result.access_token`
)
Not gonna work if
result
is a string– user184994
Sep 1 at 16:48
result
@user184994 My bad, I skimmed over it thinking it was
JSON.parse
!– Joe Iddon
Sep 1 at 16:48
JSON.parse
.subscribe( res =>
alert(res.access_token)
)
While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please include an explanation for your code, as that really helps to improve the quality of your post.
– Luca Kiebel
Sep 1 at 19:09
.subscribe( res =>
alert(res.access_token)
)
If you are unable to solve your problem by following solution..
There is no need to stringify the result.
Please try following..
.subscribe( res =>
alert(res['access_token']);
)
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Why would you like to stringify it?
– brk
Sep 1 at 16:47