{"id":207603,"date":"2025-07-08T09:35:28","date_gmt":"2025-07-08T01:35:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207603\/"},"modified":"2025-07-08T09:35:28","modified_gmt":"2025-07-08T01:35:28","slug":"%e5%ae%9a%e4%b9%89%e7%b1%bb%e5%9e%8b%e4%bb%a5%e7%94%9f%e6%88%90%e5%b5%8c%e5%a5%97-json-%e7%9a%84%e6%9b%b4%e5%a5%bd%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207603\/","title":{"rendered":"\u5b9a\u4e49\u7c7b\u578b\u4ee5\u751f\u6210\u5d4c\u5957 JSON \u7684\u66f4\u597d\u65b9\u6cd5"},"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>\u5b9a\u4e49\u7c7b\u578b\u4ee5\u751f\u6210\u5d4c\u5957 JSON \u7684\u66f4\u597d\u65b9\u6cd5<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-23 21:45:28<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2aGolang\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u5b9a\u4e49\u7c7b\u578b\u4ee5\u751f\u6210\u5d4c\u5957 JSON \u7684\u66f4\u597d\u65b9\u6cd5\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u9700\u8981\u4f7f\u7528 go \u751f\u6210\u4ee5\u4e0b json \u8f93\u51fa\u3002 <\/p>\n<pre>{\n  \"id\": \"zx222\",\n  \"links\": {\n    \"main_entity\": {\n      \"data\": [{\n        \"type\": \"car\",\n        \"id\": \"abc123\"\n      }]\n    }\n  }\n}<\/pre>\n<p>\u901a\u8fc7\u5c01\u9001\u5904\u7406\u751f\u6210\u4e0a\u8ff0 json \u7684\u76f4\u63a5\u65b9\u6cd5\u662f\u4f7f\u7528\u4ee5\u4e0b\u7c7b\u578b<\/p>\n<pre>type Element struct{\n  Id    string      `json:\"id\"`\n  Links LinksObject `json:\"links\"`\n}\n\ntype LinksObject struct{\n  MainEntity MainEntityObject `json:\"main_entity\"`\n}\n\ntype MainEntityObject struct{\n  Data []EntityDef `json:\"data\"`\n}\n\ntype EntityDef struct{\n  Type string `json:\"type\"`\n  Id   string `json:\"id\"`\n}<\/pre>\n<p>\u662f\u5426\u6709\u66f4\u597d\u7684\u65b9\u6cd5\u6765\u751f\u6210\u4e0a\u8ff0 json\uff0c\u800c\u65e0\u9700\u5b9a\u4e49\u6bcf\u4e2a\u7ed3\u6784\u53ea\u662f\u4e3a\u4e86\u5d4c\u5957\u7ed3\u6784\uff1f <\/p>\n<p>\u5728\u95ee\u9898\u80cc\u540e\u6dfb\u52a0\u4e00\u4e9b\u6211\u7684\u60f3\u6cd5\u3002\u7531\u4e8e\u6d88\u606f\u7684\u5305\u88c5\u65b9\u5f0f\uff0c\u539f\u59cb json \u5177\u6709\u989d\u5916\u7684\u5d4c\u5957\u7ea7\u522b\u3002\u4f46\u5b83\u4eec\u4e0d\u4e00\u5b9a\u5177\u6709\u4efb\u4f55\u610f\u4e49\uff0c\u5426\u5219\u5c06\u5b83\u4eec\u5b9a\u4e49\u4e3a\u4ec5\u7528\u4e8e\u89e3\u7801\/\u7f16\u7801\u4e3a json \u7684\u6570\u636e\u7c7b\u578b\u4f3c\u4e4e\u6ca1\u6709\u5fc5\u8981\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<pre>type Element struct {\n    ID    string `json:\"id\"`\n    Links struct {\n        MainEntity struct {\n            Data []struct {\n                Type string `json:\"type\"`\n                ID   string `json:\"id\"`\n            } `json:\"data\"`\n        } `json:\"main_entity\"`\n    } `json:\"links\"`\n}<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5b9a\u4e49\u7c7b\u578b\u4ee5\u751f\u6210\u5d4c\u5957 JSON \u7684\u66f4\u597d\u65b9\u6cd5\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-207603","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207603","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=207603"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207603\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}