{"id":4938,"date":"2023-01-05T11:22:30","date_gmt":"2023-01-05T03:22:30","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4938"},"modified":"2023-01-05T11:22:30","modified_gmt":"2023-01-05T03:22:30","slug":"%e5%ad%b8%e7%bf%92typescript%e4%b8%ad%e7%9a%84%e5%ad%97%e4%b8%b2url%e7%b7%a8%e7%a2%bc-%e8%a7%a3%e7%a2%bc","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92typescript%e4%b8%ad%e7%9a%84%e5%ad%97%e4%b8%b2url%e7%b7%a8%e7%a2%bc-%e8%a7%a3%e7%a2%bc\/","title":{"rendered":"\u5b78\u7fd2TypeScript\u4e2d\u7684\u5b57\u4e32URL\u7de8\u78bc\/\u89e3\u78bc"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, URL Encoding\/Decoding\"><\/p>\n<h1>TypeScript \u5b57\u4e32\u7684\u6c42 URL \u7de8\u78bc\/\u89e3\u78bc(String URL Encoding\/Decoding)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u66f4\u9ad8\u54c1\u8cea\u7684\u7a0b\u5f0f\u78bc\u3002\u5728 TypeScript \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528\u5b57\u4e32\u7684\u6c42 URL \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\u4f86\u5c0d URL \u9032\u884c\u7de8\u78bc\/\u89e3\u78bc\uff0c\u4ee5\u4fbf\u5728\u7db2\u8def\u4e0a\u50b3\u8f38\u6642\u80fd\u5920\u66f4\u5b89\u5168\u5730\u4fdd\u8b77\u8cc7\u6599\u3002<\/p>\n<h2>TypeScript \u5b57\u4e32\u7684\u6c42 URL \u7de8\u78bc\/\u89e3\u78bc\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>URL \u7de8\u78bc\/\u89e3\u78bc\u662f\u4e00\u7a2e\u5c07 URL \u4e2d\u7684\u7279\u6b8a\u5b57\u5143\u7de8\u78bc\u6210\u53ef\u4ee5\u5728\u7db2\u8def\u4e0a\u50b3\u8f38\u7684\u5b57\u5143\uff0c\u4ee5\u4fbf\u80fd\u5920\u66f4\u5b89\u5168\u5730\u4fdd\u8b77\u8cc7\u6599\u3002\u5728 TypeScript \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 encodeURIComponent() \u548c decodeURIComponent() \u5169\u500b\u51fd\u5f0f\u4f86\u5c0d URL \u9032\u884c\u7de8\u78bc\/\u89e3\u78bc\u3002<\/p>\n<h2>TypeScript \u5b57\u4e32\u7684\u6c42 URL \u7de8\u78bc\/\u89e3\u78bc\u7684\u7a0b\u5f0f\u7bc4\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528 TypeScript \u5c0d URL \u9032\u884c\u7de8\u78bc\/\u89e3\u78bc\u7684\u7a0b\u5f0f\u7bc4\u4f8b\uff1a<\/p>\n<pre class=\"brush: typescript\">\n\/\/ \u5c07 URL \u9032\u884c\u7de8\u78bc\nlet encodedURL = encodeURIComponent(\"https:\/\/www.example.com\/path\/to\/file?param1=value1&param2=value2\");\n\n\/\/ \u5c07 URL \u9032\u884c\u89e3\u78bc\nlet decodedURL = decodeURIComponent(encodedURL);\n\nconsole.log(encodedURL); \/\/ https%3A%2F%2Fwww.example.com%2Fpath%2Fto%2Ffile%3Fparam1%3Dvalue1%26param2%3Dvalue2\nconsole.log(decodedURL); \/\/ https:\/\/www.example.com\/path\/to\/file?param1=value1&param2=value2\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 encodeURIComponent() \u51fd\u5f0f\u5c07 URL \u9032\u884c\u7de8\u78bc\uff0c\u4e26\u4f7f\u7528 decodeURIComponent() \u51fd\u5f0f\u5c07 URL \u9032\u884c\u89e3\u78bc\u3002<\/p>\n<p><!--more--><\/p>\n<h2>TypeScript \u5b57\u4e32\u7684\u6c42 URL \u7de8\u78bc\/\u89e3\u78bc\u7684\u512a\u9ede<\/h2>\n<p>\u4f7f\u7528 TypeScript \u5c0d URL \u9032\u884c\u7de8\u78bc\/\u89e3\u78bc\u7684\u512a\u9ede\u6709\uff1a<\/p>\n<ul>\n<li><strong>\u5b89\u5168\u6027\uff1a<\/strong>\u4f7f\u7528 TypeScript \u5c0d URL \u9032\u884c\u7de8\u78bc\/\u89e3\u78bc\u53ef\u4ee5\u66f4\u5b89\u5168\u5730\u4fdd\u8b77\u8cc7\u6599\uff0c\u56e0\u70ba\u7de8\u78bc\u5f8c\u7684 URL \u4e0d\u6703\u88ab\u7db2\u8def\u4e0a\u7684\u60e1\u610f\u8edf\u9ad4\u8b80\u53d6\u3002<\/li>\n<li><strong>\u7c21\u55ae\u6613\u7528\uff1a<\/strong>TypeScript \u63d0\u4f9b\u4e86 encodeURIComponent() \u548c decodeURIComponent() \u5169\u500b\u51fd\u5f0f\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5c0d URL \u9032\u884c\u7de8\u78bc\/\u89e3\u78bc\u3002<\/li>\n<li><strong>\u9ad8\u6548\u7387\uff1a<\/strong>TypeScript \u7684\u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\u53ef\u4ee5\u63d0\u9ad8\u958b\u767c\u8005\u7684\u5de5\u4f5c\u6548\u7387\uff0c\u56e0\u70ba\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5728\u77ed\u6642\u9593\u5167\u5b8c\u6210\u7de8\u78bc\/\u89e3\u78bc\u7684\u5de5\u4f5c\u3002<\/li>\n<\/ul>\n<h2>\u7e3d\u7d50<\/h2>\n<p>TypeScript \u63d0\u4f9b\u4e86\u5b57\u4e32\u7684\u6c42 URL \u7de8\u78bc\/\u89e3\u78bc\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u5c0d URL \u9032\u884c\u7de8\u78bc\/\u89e3\u78bc\uff0c\u4ee5\u4fbf\u5728\u7db2\u8def\u4e0a\u50b3\u8f38\u6642\u80fd\u5920\u66f4\u5b89\u5168\u5730\u4fdd\u8b77\u8cc7\u6599\u3002\u4f7f\u7528 TypeScript \u5c0d URL \u9032\u884c\u7de8\u78bc\/\u89e3\u78bc\u7684\u512a\u9ede\u6709\u5b89\u5168\u6027\u3001\u7c21\u55ae\u6613\u7528\u3001\u9ad8\u6548\u7387\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u4e2d\u7684\u5b57\u4e32URL\u7de8\u78bc\/\u89e3\u78bc\uff0c\u8a73\u7d30\u89e3\u91cbencodeURI()\u3001encodeURIComponent()\u3001decodeURI()\u548cdecodeURIComponent()\u51fd\u6578\u7684\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u5011\u4f86\u5c0dURL\u9032\u884c\u7de8\u78bc\u548c\u89e3\u78bc\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-4938","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1hE","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=4938"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4938\/revisions"}],"predecessor-version":[{"id":4939,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4938\/revisions\/4939"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}