javascript - 如何将令牌转换为所需的格式?
问题描述
如何将令牌转换为所需的格式?
我通过 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}
解决方案
使用 decodeURI:
let string = '{%22token%22:%225ecc2023eb593303e6dea15f5ec775874d656203fdb401805ecc2023eb593303e6dea160%22,%22expiredAt%22:1590522275554,%22timeZone%22:%22Europe/Moscow%22,%22active%22:true}'
console.log(decodeURI(string))
推荐阅读
- python - Unittest中的ANTLR4 Python:如何中止任何错误
- python - 递归 FizzBuzz 函数 - 将值存储在列表中
- php - 如何在 php 中使用 cookie 添加到购物车
- python - 无法用heroku构建conda
- php - WooCommerce:如何在管理产品列表中的产品名称旁边添加产品类型
- javascript - window.onload (JavaScript) 中的 select.onchange
- mongodb - MongoDB 项目除嵌入字段中的一个之外的所有值
- json - 空手道 API 框架 - 如何断言键的空值,如果该值为空,则断言不应存在其他键
- javascript - 创建聊天机器人,但在终端中使用访问令牌执行时出现授权错误
- powermockito - 将 jdk8 升级到 JDK11 时 PowerMockito.mockStatic() 处的 org.powermock.api.mockito.ClassNotPreparedException