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





Why would you like to stringify it?
– brk
Sep 1 at 16:47





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế