URL ENCODER / DECODER
URL 编解码,中文参数不出错。
把 URL 或查询参数编码成安全字符,或把 %XX 还原成原文,区分整段 URL 与单个参数两种场景。
本页处理在浏览器本地完成
这个工具能做什么?
“编码参数”会转义包括 & = ? 在内的所有特殊字符,适合放进查询字符串;“编码整段 URL”只转义必要字符,保留网址结构。解码则按对应规则还原。
常见问题
component 和 URI 有什么区别?
component(encodeURIComponent)会编码更多字符,适合单个参数;URI(encodeURI)保留 : / ? & 等,适合整条网址。
内容会上传吗?
不会。编解码都在当前浏览器内完成。
示例与注意事项Example & notes
一个例子A worked example
搜索词含空格和中文时,编码后变成 %E5%9B%BE%E8%AF%B4%20…,粘到接口或链接里就不会被截断或报错。A query containing spaces and Chinese characters becomes %E5%9B%BE%E8%AF%B4%20… so it survives intact in a URL or API call.
注意事项Things to watch
- 区分两种模式:encodeURIComponent 适合参数值,encodeURI 会保留 :/?&= 等结构字符。Two modes matter: encodeURIComponent for parameter values, encodeURI when the URL structure must stay readable.
- 不要重复编码,否则 %20 会变成 %2520,接口会收到多余的两个字符。Do not double-encode: %20 turns into %2520 and the API receives two extra characters.
- 加号(+)在表单里代表空格,但在 JSON/URL 里应写成 %2B,混用常导致参数错位。A plus sign means space in form encoding but must be %2B in URLs and JSON — mixing them shifts parameters.
相关问答More Q&A
什么时候用哪种编码?Which mode should I use?
拼参数值时用 encodeURIComponent;整条链接需要保留结构符号时用 encodeURI。Use encodeURIComponent for values, encodeURI when the whole URL must keep its structure characters.
中文编码后为什么变这么长?Why does Chinese text get so long after encoding?
每个汉字在 UTF-8 下占 3 字节,百分号编码后是 9 个字符,所以长度会变成原来的 3 倍。Each Chinese character is three UTF-8 bytes, which percent-encoding expands to nine characters — a threefold increase.