-2

如何将令牌转换为所需的格式?

我通过 urlParams 从 profile.damain.com 上的 domain.com 获取令牌

  testConfirm = () => {
    if(window.location.href = 'http://localhost:3000') {
      const req = localStorage.getItem('accessToken')
      JSON.parse(req)
      window.location.href = `http://1.localhost:3000?token=${req}`
      return true
    }
  }

现在它是这样的:

{%22token%22:%225ecc2023eb593303e6dea15f5ec775874d656203fdb401805ecc2023eb593303e6dea160%22,%22expiredAt%22:1590522275554,%22timeZone%22:%22Europe/Moscow%22,%22active%22:true}

如所须: {"token":"5eccbf2e94b981c418d675355ec777c894b981c4185100a75eccbf2e94b981c418d67536","expiredAt":1590562990267,"timeZone":"Europe/Moscow","active":true}

4

1 回答 1

0

使用 decodeURI:

let string = '{%22token%22:%225ecc2023eb593303e6dea15f5ec775874d656203fdb401805ecc2023eb593303e6dea160%22,%22expiredAt%22:1590522275554,%22timeZone%22:%22Europe/Moscow%22,%22active%22:true}'


console.log(decodeURI(string))

于 2020-05-26T09:07:22.100 回答