当我做:
encodeURIComponent('Cancún, Mexico');
它返回:
Canc%C3%BAn%2C%20Mexico
据此: http: //www.degraeve.com/reference/urlencoding.php
字符:ú
应该是%FA
,但它%C3%BA
为什么会这样,我如何解决这个问题而不必做很多字符串替换?
当我做:
encodeURIComponent('Cancún, Mexico');
它返回:
Canc%C3%BAn%2C%20Mexico
据此: http: //www.degraeve.com/reference/urlencoding.php
字符:ú
应该是%FA
,但它%C3%BA
为什么会这样,我如何解决这个问题而不必做很多字符串替换?
据此: http: //www.degraeve.com/reference/urlencoding.php字符:ú 应该是 %FA 而不是它的 %C3%BA 为什么会这样以及如何解决这个问题而不必做很多字符串替换?
您根本不需要修复任何东西。根据https://en.wikipedia.org/wiki/Percent-encoding(更相关的是https://www.rfc-editor.org/rfc/rfc3986):
数据应首先根据 UTF-8 字符编码被编码为八位字节,然后只有那些八位字节 [...] 应进行百分比编码。
因此,%C3%BA
是 的完全正确编码ú
,它不是未保留的 ASCII 范围内的字符。