{"id":206981,"date":"2025-07-08T08:05:06","date_gmt":"2025-07-08T00:05:06","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206981\/"},"modified":"2025-07-08T08:05:06","modified_gmt":"2025-07-08T00:05:06","slug":"%e6%88%91%e5%8f%af%e4%bb%a5%e4%bd%bf%e7%94%a8%e4%bb%80%e4%b9%88%e7%bb%93%e6%9e%84%e6%9d%a5%e8%a7%a3%e7%a0%81%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e7%9a%84-json-%e6%95%b0%e7%bb%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206981\/","title":{"rendered":"\u6211\u53ef\u4ee5\u4f7f\u7528\u4ec0\u4e48\u7ed3\u6784\u6765\u89e3\u7801\u5b57\u7b26\u4e32\u6570\u7ec4\u7684 JSON \u6570\u7ec4\uff1f"},"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>\u6211\u53ef\u4ee5\u4f7f\u7528\u4ec0\u4e48\u7ed3\u6784\u6765\u89e3\u7801\u5b57\u7b26\u4e32\u6570\u7ec4\u7684 JSON \u6570\u7ec4\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 10:36:36<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u6211\u53ef\u4ee5\u4f7f\u7528\u4ec0\u4e48\u7ed3\u6784\u6765\u89e3\u7801\u5b57\u7b26\u4e32\u6570\u7ec4\u7684 JSON \u6570\u7ec4\uff1f\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u9700\u8981\u5728 golang \u4e2d\u89e3\u7801\u4ee5\u4e0b json\uff1a<\/p>\n<pre>{\n   \"name\":\"test\",\n   \"tags\":[\n      [\n         \"browser\",\n         \"chrome 28.0.1500\"\n      ],\n      [\n         \"browser.name\",\n         \"chrome\"\n      ]\n   ]\n}<\/pre>\n<p>\u6211\u5e26\u6765\u4e86\u4e00\u4e9b\u7ed3\u6784\u548c\u4e00\u4e9b\u53d8\u4f53\uff0c\u4f46\u5b83\u4ecd\u7136\u4e0d\u8d77\u4f5c\u7528\uff1a<\/p>\n<pre>type Response struct {\n  Name string `json:\"name\"`\n  Tags map[int][]string `json:\"tags\"`\n}<\/pre>\n<p>https:\/\/play.golang.org\/p\/wuvehdlcs6h<\/p>\n<p>\u600e\u6837\u624d\u80fd\u8fbe\u5230\u9884\u671f\u7684\u6548\u679c\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p><code>\"tags\"<\/code> \u662f\u4fdd\u5b58 <code>string<\/code> \u503c\u7684\u6570\u7ec4\u7684\u6570\u7ec4\u3002\u56e0\u6b64\u53ea\u9700\u5728 go \u4e2d\u4f7f\u7528 <code>[][]string<\/code> \u6765\u5efa\u6a21\u5373\u53ef\uff1a<\/p>\n<pre>type response struct {\n    name string     `json:\"name\"`\n    tags [][]string `json:\"tags\"`\n}<\/pre>\n<p>\u89e3\u7ec4\u6253\u5370 <code>response<\/code> \u540e\uff1a<\/p>\n<pre>fmt.printf(\"%+v\", response)<\/pre>\n<p>\u8f93\u51fa\u4e3a\uff08\u5728 \u4e0a\u5c1d\u8bd5\uff09\uff1a<\/p>\n<pre>{Name:test Tags:[[browser Chrome 28.0.1500] [browser.name Chrome]]}<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u6211\u53ef\u4ee5\u4f7f\u7528\u4ec0\u4e48\u7ed3\u6784\u6765\u89e3\u7801\u5b57\u7b26\u4e32\u6570\u7ec4\u7684 JSON \u6570\u7ec4\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\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-206981","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206981","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=206981"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206981\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}