{"id":206243,"date":"2025-06-12T12:26:47","date_gmt":"2025-06-12T04:26:47","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206243\/"},"modified":"2025-06-12T12:26:47","modified_gmt":"2025-06-12T04:26:47","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-go-%e8%af%ad%e8%a8%80%e5%b0%86%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e8%bd%ac%e6%8d%a2%e4%b8%ba%e7%9b%ae%e5%bd%95%e7%bb%93%e6%9e%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206243\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u76ee\u5f55\u7ed3\u6784\uff1f"},"content":{"rendered":"<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u76ee\u5f55\u7ed3\u6784\uff1f\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241107\/1730950254672c346e1f498.jpg\" class=\"aligncenter\">,<br \/>\n<strong>go \u8bed\u8a00\u5b9e\u73b0\u4e8c\u7ef4\u6570\u7ec4\u5230\u76ee\u5f55\u7ed3\u6784\u8f6c\u6362<\/strong>,\u60a8\u60f3\u5b9e\u73b0\u4e00\u4e2a\u7c7b\u4f3c\u4e8e rdm \u7684\u76ee\u5f55\u6811\uff0c\u5e76\u4ece\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u751f\u6210\u8be5\u7ed3\u6784\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u6b64\u7b97\u6cd5\u7684\u65b9\u6cd5\uff1a,\u9996\u5148\uff0c\u4f7f\u7528\u5192\u53f7\u5206\u5272\u952e\uff0c\u521b\u5efa\u952e\u7684\u6570\u7ec4\u3002\u7136\u540e\uff0c\u904d\u5386\u8be5\u6570\u7ec4\u5e76\u6784\u5efa\u76ee\u5f55\u7ed3\u6784\u3002,\u4e0a\u8ff0\u7b97\u6cd5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u904d\u5386\u6570\u7ec4\uff1a,\u901a\u8fc7\u4f7f\u7528\u8fd9\u79cd\u6df1\u5ea6\u904d\u5386\u7684\u65b9\u6cd5\uff0c\u7b97\u6cd5\u6784\u5efa\u76ee\u5f55\u7ed3\u6784\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u8def\u5f84\u8868\u793a\u5176\u5728\u6811\u4e2d\u7684\u4f4d\u7f6e\u3002,\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301GOLANG\uff01\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u3002,\u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u904d\u5386\u8def\u5f84\u7684\u6bcf\u4e2a\u90e8\u5206\u3002,\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u952e\u6570\u7ec4\uff0c\u4f7f\u7528\u5192\u53f7\u5c06\u5176\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u8def\u5f84\u3002,\u5982\u679c\u8282\u70b9\u5b58\u5728\uff0c\u5219\u79fb\u81f3\u8be5\u8282\u70b9\u3002,go \u8bed\u8a00\u5b9e\u73b0\u4e8c\u7ef4\u6570\u7ec4\u5230\u76ee\u5f55\u7ed3\u6784\u8f6c\u6362,\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u76ee\u5f55\u7ed3\u6784\uff1f\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01,<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\u4f7f\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u76ee\u5f55\u7ed3\u6784\uff1f<\/span><\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u76ee\u5f55\u7ed3\u6784\uff1f<\/h1>\n<p><span>2024-11-07 11:31:09<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u76ee\u5f55\u7ed3\u6784\uff1f\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241107\/1730950254672c346e1f498.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>go \u8bed\u8a00\u5b9e\u73b0\u4e8c\u7ef4\u6570\u7ec4\u5230\u76ee\u5f55\u7ed3\u6784\u8f6c\u6362<\/strong><\/p>\n<p>\u60a8\u60f3\u5b9e\u73b0\u4e00\u4e2a\u7c7b\u4f3c\u4e8e rdm \u7684\u76ee\u5f55\u6811\uff0c\u5e76\u4ece\u4e8c\u7ef4\u6570\u7ec4\u4e2d\u751f\u6210\u8be5\u7ed3\u6784\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u6b64\u7b97\u6cd5\u7684\u65b9\u6cd5\uff1a<\/p>\n<p>\u9996\u5148\uff0c\u4f7f\u7528\u5192\u53f7\u5206\u5272\u952e\uff0c\u521b\u5efa\u952e\u7684\u6570\u7ec4\u3002\u7136\u540e\uff0c\u904d\u5386\u8be5\u6570\u7ec4\u5e76\u6784\u5efa\u76ee\u5f55\u7ed3\u6784\u3002<\/p>\n<pre>import (\n    \"encoding\/json\"\n    \"strings\"\n)\n\ntype Node struct {\n    Name  string\n    Value string\n    Child map[string]Node\n}\n\nfunc main() {\n    keys := [][]string{\n        []string{\"answer\", \"aa\", \"bb\"},\n        []string{\"answer\", \"aa\", \"cc\"},\n        []string{\"question\", \"book1\"},\n        []string{\"question\", \"book1\", \"answer\"},\n        []string{\"question\", \"book1\", \"answer\", \"name1\"},\n        []string{\"question\", \"book1\", \"answer\", \"name2\"},\n    }\n\n    root := Node{\n        Name:  \"\",\n        Value: \"\",\n        Child: make(map[string]Node),\n    }\n\n    for _, key := range keys {\n        t := &amp;root\n        for _, k := range key {\n            if _, has := t.Child[k]; has {\n                t = &amp;t.Child[k]\n            } else {\n                t.Child[k] = Node{\n                    Name:  k,\n                    Value: strings.Join(key, \":\"),\n                    Child: make(map[string]Node),\n                }\n                t = &amp;t.Child[k]\n            }\n        }\n    }\n    r, _ := json.Marshal(&amp;root)\n    println(string(r))\n}<\/pre>\n<p>\u4e0a\u8ff0\u7b97\u6cd5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u904d\u5386\u6570\u7ec4\uff1a<\/p>\n<ul>\n<li>\u5bf9\u4e8e\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u952e\u6570\u7ec4\uff0c\u4f7f\u7528\u5192\u53f7\u5c06\u5176\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u8def\u5f84\u3002<\/li>\n<li>\u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u904d\u5386\u8def\u5f84\u7684\u6bcf\u4e2a\u90e8\u5206\u3002<\/li>\n<li>\u5982\u679c\u8282\u70b9\u5b58\u5728\uff0c\u5219\u79fb\u81f3\u8be5\u8282\u70b9\u3002<\/li>\n<li>\u5426\u5219\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u8282\u70b9\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u7236\u8282\u70b9\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u79cd\u6df1\u5ea6\u904d\u5386\u7684\u65b9\u6cd5\uff0c\u7b97\u6cd5\u6784\u5efa\u76ee\u5f55\u7ed3\u6784\uff0c\u5176\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u8def\u5f84\u8868\u793a\u5176\u5728\u6811\u4e2d\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301GOLANG\uff01\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   C# \u8c03\u7528 Python3 \u7a0b\u5e8f\u65f6\u5982\u4f55\u663e\u793a\u7a97\u53e3\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   Vue \u4e2d v-nodes \u7ec4\u4ef6\u7684\u4f7f\u7528\uff1a\u5982\u4f55\u5224\u65ad prop \u7c7b\u578b\u5e76\u52a8\u6001\u6e32\u67d3\u5185\u5bb9\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86 &#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-206243","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206243","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=206243"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206243\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}