gpt4 book ai didi

javascript - decodeURIComponent 抛出错误 'URI malformed'

转载 作者:行者123 更新时间:2023-11-30 12:29:57 32 4
gpt4 key购买 nike

由于 unescape 已被弃用,我选择了 decodeURIComponent ,但它没有按预期工作。 decodeURIComponent 无法解码以下 URI 组件

Coast%20Guard%20Academy%20to%20hold%20annual%20Women%92s%20%91Leadhership%92%20event

解码上述字符串时,decodeURIComponent 会抛出一个错误,这将阻止剩余的 javascript 执行。

有解决办法吗?

最佳答案

%91%92 字符使用 ANSI 代码页编码。 decodeURIComponent() expects the string to have been encoded as UTF-8 :

The decodeURIComponent function computes a new version of a URI in which each escape sequence and UTF-8 encoding of the sort that might be introduced by the encodeURIComponent function is replaced with the character that it represents.

这两个引号应编码为 %E2%80%98%E2%80%99

关于javascript - decodeURIComponent 抛出错误 'URI malformed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28063750/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com