简体   繁体   中英

How to convert token to the desired format?

How to convert token to the desired format?

I get token from domain.com on profile.damain.com via urlParams

  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
    }
  }

Now it comes like this:

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

As needed: {"token":"5eccbf2e94b981c418d675355ec777c894b981c4185100a75eccbf2e94b981c418d67536","expiredAt":1590562990267,"timeZone":"Europe/Moscow","active":true}

Use decodeURI:

 let string = '{%22token%22:%225ecc2023eb593303e6dea15f5ec775874d656203fdb401805ecc2023eb593303e6dea160%22,%22expiredAt%22:1590522275554,%22timeZone%22:%22Europe/Moscow%22,%22active%22:true}' console.log(decodeURI(string))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM