{"id":207970,"date":"2025-07-08T12:49:51","date_gmt":"2025-07-08T04:49:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207970\/"},"modified":"2025-07-08T12:49:51","modified_gmt":"2025-07-08T04:49:51","slug":"go%e4%b8%adjson%e5%ba%8f%e5%88%97%e5%8c%96%e5%90%8e%e7%9a%84anonymus%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207970\/","title":{"rendered":"go\u4e2djson\u5e8f\u5217\u5316\u540e\u7684Anonymus\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>go\u4e2djson\u5e8f\u5217\u5316\u540e\u7684Anonymus\u7ed3\u6784<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-27 14:15:37<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6765\u5230\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60Golang\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300ago\u4e2djson\u5e8f\u5217\u5316\u540e\u7684Anonymus\u7ed3\u6784\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u60f3\u5b9e\u73b0\u8fd9\u6837\u7684\u8f93\u51fajson\u683c\u5f0f<\/p>\n<pre>{\n    \"2019-07-22\": {\n        \"something\": {\n            \"type\": \"entry\",\n            \"id\": 1766617,\n        },\n        \"something2\": {\n            \"type\": \"entry\",\n            \"id\": 1766617,\n        },\n    },\n    \"2019-07-23\": {\n        \"something\": {\n            \"type\": \"entry\",\n            \"id\": 1766618,\n        },\n        \"something2\": {\n            \"type\": \"entry\",\n            \"id\": 1766620,\n        },\n    },\n}<\/pre>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u5df2\u5c06\u8fd9\u4e9b\u6570\u636e\u5206\u6210 3 \u4e2a\u7ed3\u6784\uff1a<\/p>\n<pre>type response struct {\n    days map[string]day\n}\n\ntype day struct {\n    entries map[string]entry\n}\n\ntype entry struct {\n    type            string `json:\"type\"`\n    id              int    `json:\"id\"`\n}\n<\/pre>\n<p>\u5e8f\u5217\u5316\u4e3a json \u540e\uff0c\u6211\u7684\u7ed3\u6784\u5305\u542b\u5b57\u6bb5\u540d\u79f0\u548c\u5d4c\u5957 json \u5bf9\u8c61\uff0c\u8fd9\u662f\u9519\u8bef\u7684\uff1a<\/p>\n<pre>{\n    \"Days\": {\n        \"2019-07-22\": {\n            \"Entries\": {\n                \"something\": {\n                    \"type\": \"ENTRY\",\n                    \"id\": 1766617\n                },\n                \"something2\": {\n                    \"type\": \"ENTRY\",\n                    \"id\": 1766617\n                }\n            }\n        }\n    }\n}<\/pre>\n<p>\u662f\u5426\u53ef\u4ee5\u8df3\u8fc7 <code>response:days<\/code> \u548c <code>day:entries<\/code> \u5b57\u6bb5\u4e2d\u7684\u8fd9\u4e9b\u5b57\u6bb5\u540d\u79f0\uff1f\u6211\u4e0d\u4f1a\u5c06 json \u53cd\u5e8f\u5217\u5316\u4e3a\u7ed3\u6784\uff0c\u6240\u4ee5\u552f\u4e00\u7684\u95ee\u9898\u662f\u5e8f\u5217\u5316\u3002\u7531\u4e8e bc \u7834\u574f\uff0c\u6211\u65e0\u6cd5\u66f4\u6539 json \u7ed3\u6784\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u8981\u5b9e\u73b0\u60a8\u60f3\u8981\u7684 json\uff0c\u60a8\u7684 <code>response<\/code> \u7c7b\u578b\u5e94\u8be5\u662f\u5730\u56fe\u7684\u5730\u56fe\u3002<\/p>\n<pre>type Response map[string]map[string]Entry\n\ntype Entry struct {\n    Type string `json:\"type\"`\n    Id   int    `json:\"id\"`\n}<\/pre>\n<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300ago\u4e2djson\u5e8f\u5217\u5316\u540e\u7684Anonymus\u7ed3\u6784\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/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-207970","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207970","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=207970"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207970\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}