{"id":207681,"date":"2025-07-08T08:39:38","date_gmt":"2025-07-08T00:39:38","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207681\/"},"modified":"2025-07-08T08:39:38","modified_gmt":"2025-07-08T00:39:38","slug":"%e6%b2%a1%e6%9c%89%e5%a3%b0%e6%98%8e%e7%b1%bb%e5%9e%8b%e7%9a%84%e5%b5%8c%e5%a5%97%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207681\/","title":{"rendered":"\u6ca1\u6709\u58f0\u660e\u7c7b\u578b\u7684\u5d4c\u5957\u7ed3\u6784"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u6ca1\u6709\u58f0\u660e\u7c7b\u578b\u7684\u5d4c\u5957\u7ed3\u6784<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-24 16:30:25<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u6ca1\u6709\u58f0\u660e\u7c7b\u578b\u7684\u5d4c\u5957\u7ed3\u6784\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u77e5\u9053\u6211\u4eec\u53ef\u4ee5\u505a\u4e00\u4e9b\u6216\u591a\u6216\u5c11\u50cf\u8fd9\u6837\u7684\u4e8b\u60c5\uff1a<\/p>\n<pre>type struct1 struct {\n    somestring string\n    someint    int\n}\n\ntype struct2 struct {\n    somestring string\n    somestruct []struct1\n}\n\nvar s struct2 = struct2{\"abc\", []{struct1{\"def\", 123}, struct1{\"ghi\", 456}}}\n<\/pre>\n<p>\u4f46\u6211\u60f3\u77e5\u9053\u60a8\u662f\u5426\u53ef\u4ee5\u5bf9\u6211\u5728\u7279\u5b9a\u4f4d\u7f6e\u4e4b\u5916\u7684\u5176\u4ed6\u4efb\u4f55\u5730\u65b9\u90fd\u4e0d\u9700\u8981\u7684\u6570\u636e\u8fdb\u884c\u533f\u540d\u5904\u7406\u3002\u6211\u60f3\u907f\u514d\u7f16\u5199\u591a\u4f59\u7684\u4ee3\u7801\uff0c\u6211\u6b63\u5728\u5bfb\u627e\u8fd9\u6837\u7684\u4e1c\u897f\uff1a<\/p>\n<pre>var s = struct {\n        someString string, someStructs[] struct {\n            x string, y int\n        }\n    } {\n        \"ok\", []{\n            {1, 2}, {3, 4}, {5, 6}\n        }\n    }\n<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u662f\u7684\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u505a\uff0c\u4f46\u662f\u5982\u679c\u4f60\u5d4c\u5957\u4e86\u533f\u540d\u7ed3\u6784\uff0c\u90a3\u5c31\u6709\u70b9\u4e4f\u5473\u4e86\uff1a<\/p>\n<pre>var s = struct {\n        someString string, \n        someStructs[] struct {\n            x string\n            y int\n        }\n } {\n  someString: \"ok\",\n  someStructs: []struct{ x string, y int } {\n            {\"1\", 2}, {\"3\", 4}, {\"5\", 6}\n        }\n }<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u6ca1\u6709\u58f0\u660e\u7c7b\u578b\u7684\u5d4c\u5957\u7ed3\u6784\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#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-207681","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207681","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=207681"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207681\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}