首页 > 解决方案 > 如何从 json.stringify 中读取特定值:离子

问题描述

从帖子中我得到了一个资源

.subscribe( res => {
    let result = JSON.stringify(res);
    alert(result)
})

& 作为alert(result)我得到的回应

{"access_token": "hjhdshJHUHYI67HUjhhk98BJ_BJHBBHbnbhbhbjh_jmnhghmghgfffgxcgfcf98hujh",
 "expires_in":"518399"}

在这里,我想读取access_token值并将其保存在变量中我该怎么做?

标签: javascriptangulartypescriptionic2

解决方案


您不必进行字符串化,只需将其作为res.access_token

.subscribe((res:any) => {
  let result = res.access_token;
  alert(result)
})

推荐阅读