{"id":206043,"date":"2025-06-12T11:52:45","date_gmt":"2025-06-12T03:52:45","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206043\/"},"modified":"2025-06-12T11:52:45","modified_gmt":"2025-06-12T03:52:45","slug":"%e5%a6%82%e4%bd%95%e8%ae%a9-go-map-%e7%9a%84%e5%80%bc%e7%b1%bb%e5%9e%8b%e5%90%8c%e6%97%b6%e6%94%af%e6%8c%81-string-%e5%92%8c-int-%e7%b1%bb%e5%9e%8b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206043\/","title":{"rendered":"\u5982\u4f55\u8ba9 Go Map \u7684\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\uff1f"},"content":{"rendered":"<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300a\u5982\u4f55\u8ba9 Go Map \u7684\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9GOLANG\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7GOLANG\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241101\/17304565086724abbc33398.jpg\" class=\"aligncenter\">,<br \/>\n<strong>go map \u7c7b\u578b\u7075\u6d3b\u6027<\/strong>,golang \u7684 map \u662f\u4e00\u79cd\u952e\u503c\u5bf9\u6570\u636e\u7ed3\u6784\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u952e\u548c\u503c\u7c7b\u578b\u662f\u56fa\u5b9a\u7684\u3002\u4f46\u662f\uff0c\u6709\u65f6\u6211\u4eec\u5e0c\u671b map \u7684\u503c\u7c7b\u578b\u53ef\u4ee5\u5bb9\u7eb3\u591a\u79cd\u7c7b\u578b\u3002,\u95ee\u9898\u4e2d\u63d0\u5230\uff0c\u9ed8\u8ba4\u7684 map \u503c\u7c7b\u578b\u5b9a\u4e49\u4e3a string\uff0c\u90a3\u4e48\u5982\u4f55 \u8ba9\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\u5462\uff1f,\u7b54\u6848\u662f\u4f7f\u7528 interface{}\u3002interface{} \u662f\u4e00\u4e2a\u901a\u914d\u7c7b\u578b\uff0c\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\u3002\u901a\u8fc7\u5c06 map \u7684\u503c\u7c7b\u578b\u5b9a\u4e49\u4e3a interface{}\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e0a\u8ff0\u9700\u6c42\uff1a,\u73b0\u5728\uff0cparams \u7684\u503c\u7c7b\u578b\u4e0d\u518d\u9650\u4e8e string\uff0c\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\uff0c\u5305\u62ec string\u3001int\u3001float\u3001struct \u7b49\u3002,\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5411 map \u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9\uff1a,\u6b64\u65f6\uff0cname \u7684\u503c\u7c7b\u578b\u4e3a string\uff0c\u800c age \u7684\u503c\u7c7b\u578b\u4e3a int\u3002map \u53ef\u4ee5\u540c\u65f6\u6301\u6709\u4e0d\u540c\u7c7b\u578b\u7684\u503c\uff0c\u6ee1\u8db3\u4e86\u6211\u4eec\u7684\u9700\u6c42\u3002,\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u8ba9 Go Map \u7684\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u5427\uff01,go map \u7c7b\u578b\u7075\u6d3b\u6027,\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300a\u5982\u4f55\u8ba9 Go Map \u7684\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9GOLANG\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7GOLANG\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5982\u4f55\u8ba9 Go Map \u7684\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\uff1f<\/span><\/p>\n<h1>\u5982\u4f55\u8ba9 Go Map \u7684\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\uff1f<\/h1>\n<p><span>2024-11-01 18:22:03<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300a\u5982\u4f55\u8ba9 Go Map \u7684\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9GOLANG\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7GOLANG\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241101\/17304565086724abbc33398.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>go map \u7c7b\u578b\u7075\u6d3b\u6027<\/strong><\/p>\n<p>golang \u7684 map \u662f\u4e00\u79cd\u952e\u503c\u5bf9\u6570\u636e\u7ed3\u6784\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u952e\u548c\u503c\u7c7b\u578b\u662f\u56fa\u5b9a\u7684\u3002\u4f46\u662f\uff0c\u6709\u65f6\u6211\u4eec\u5e0c\u671b map \u7684\u503c\u7c7b\u578b\u53ef\u4ee5\u5bb9\u7eb3\u591a\u79cd\u7c7b\u578b\u3002<\/p>\n<p>\u95ee\u9898\u4e2d\u63d0\u5230\uff0c\u9ed8\u8ba4\u7684 map \u503c\u7c7b\u578b\u5b9a\u4e49\u4e3a string\uff0c\u90a3\u4e48\u5982\u4f55 \u8ba9\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\u5462\uff1f<\/p>\n<p>\u7b54\u6848\u662f\u4f7f\u7528 interface{}\u3002interface{} \u662f\u4e00\u4e2a\u901a\u914d\u7c7b\u578b\uff0c\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\u3002\u901a\u8fc7\u5c06 map \u7684\u503c\u7c7b\u578b\u5b9a\u4e49\u4e3a interface{}\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e0a\u8ff0\u9700\u6c42\uff1a<\/p>\n<pre>params := make(map[string]interface{})<\/pre>\n<p>\u73b0\u5728\uff0cparams \u7684\u503c\u7c7b\u578b\u4e0d\u518d\u9650\u4e8e string\uff0c\u53ef\u4ee5\u5bb9\u7eb3\u4efb\u4f55\u7c7b\u578b\uff0c\u5305\u62ec string\u3001int\u3001float\u3001struct \u7b49\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5411 map \u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9\uff1a<\/p>\n<pre>params[\"name\"] = \"John\"\nparams[\"age\"] = 30<\/pre>\n<p>\u6b64\u65f6\uff0cname \u7684\u503c\u7c7b\u578b\u4e3a string\uff0c\u800c age \u7684\u503c\u7c7b\u578b\u4e3a int\u3002map \u53ef\u4ee5\u540c\u65f6\u6301\u6709\u4e0d\u540c\u7c7b\u578b\u7684\u503c\uff0c\u6ee1\u8db3\u4e86\u6211\u4eec\u7684\u9700\u6c42\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u8ba9 Go Map \u7684\u503c\u7c7b\u578b\u540c\u65f6\u652f\u6301 string \u548c int \u7c7b\u578b\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   Python \u5982\u4f55\u4f18\u96c5\u5730\u5224\u65ad\u51fd\u6570\u53c2\u6570\u662f\u5426\u90fd\u662f\u6570\u5b57\u7c7b\u578b\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u4e3a\u521d\u5b66\u8005\u4f7f\u7528 Flexbox \u6784\u5efa\u7b80\u5355\u7684\u54cd\u5e94\u5f0f\u5e03\u5c40\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-206043","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=206043"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206043\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}