{"id":206753,"date":"2025-06-12T08:41:15","date_gmt":"2025-06-12T00:41:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206753\/"},"modified":"2025-06-12T08:41:15","modified_gmt":"2025-06-12T00:41:15","slug":"go-%e5%88%87%e7%89%87%e8%bd%ac-json-%e4%b8%ba%e7%a9%ba%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%e5%af%bc%e5%87%ba%e6%88%90%e5%91%98%e5%92%8c-json-%e7%bb%93%e6%9e%84%e4%b8%8d%e5%8c%b9%e9%85%8d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206753\/","title":{"rendered":"Go \u5207\u7247\u8f6c JSON \u4e3a\u7a7a\uff1a\u5982\u4f55\u89e3\u51b3\u5bfc\u51fa\u6210\u5458\u548c JSON \u7ed3\u6784\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f"},"content":{"rendered":"<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u5207\u7247\u8f6c JSON \u4e3a\u7a7a\uff1a\u5982\u4f55\u89e3\u51b3\u5bfc\u51fa\u6210\u5458\u548c JSON \u7ed3\u6784\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728GOLANG\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732196941673f3a4d3d509.jpg\" class=\"aligncenter\">,<br \/>\n<strong>go \u5207\u7247\u8f6c json \u4e3a\u7a7a\u7684\u95ee\u9898\u89e3\u6790<\/strong>,\u5728 go \u8bed\u8a00\u4e2d\uff0c\u5207\u7247\u8f6c json \u9047\u5230\u7a7a\u6570\u7ec4\u7684\u95ee\u9898\uff0c\u53ef\u80fd\u6e90\u81ea\u4ee5\u4e0b\u539f\u56e0\uff1a,<br \/>\n<strong>\u5bfc\u51fa\u6210\u5458\u548c json \u7ed3\u6784\u4e0d\u7b26<\/strong>,go \u53ea\u4f1a\u5e8f\u5217\u5316\u5bfc\u51fa\uff08\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\uff09\u7ed3\u6784\u6210\u5458\u3002\u5982\u679c\u5207\u7247\u5143\u7d20\u7c7b\u578b\u4e2d\u7684\u6210\u5458\u662f\u5c0f\u5199\u5f00\u5934\u7684\uff0c\u5219\u8fd9\u4e9b\u6210\u5458\u5c06\u4e0d\u4f1a\u5305\u542b\u5728 json \u8868\u793a\u4e2d\uff0c\u5bfc\u81f4\u7a7a\u6570\u7ec4\u3002,\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u4fee\u6539\u7ed3\u6784\u4f53\u7684\u6210\u5458\u540d\u79f0\uff0c\u4f7f\u5176\u9996\u5b57\u6bcd\u5927\u5199\u3002,<br \/>\n<strong>json struct tag \u6307\u5b9a\u4e0d\u5f53<\/strong>,json struct tag \u53ef\u4ee5\u6307\u5b9a json \u4e2d\u7684\u540d\u79f0\u3002\u5982\u679c\u6307\u5b9a\u7684\u540d\u79f0\u4e0d\u5b58\u5728\uff0c\u5219\u8be5\u6210\u5458\u5c06\u88ab\u5ffd\u7565\u3002,\u4ee5\u4e0b\u4ee3\u7801\u4e2d\u7684 sfz \u6210\u5458\u4f7f\u7528\u4e86 json struct tag \u6307\u5b9a\u4e86\u4e0d\u540c\u7684 json \u540d\u79f0\uff0c\u4f46\u8be5\u540d\u79f0\u4e0d\u5b58\u5728\uff0c\u5bfc\u81f4\u8be5\u6210\u5458\u88ab\u5ffd\u7565\uff0c\u5207\u7247\u8f6c json \u540e\u4e3a\u7a7a\u3002,\u4fee\u6539 json struct tag\uff0c\u4f7f\u7528\u6b63\u786e\u7684\u540d\u79f0\u5373\u53ef\u3002,\u672c\u7bc7\u5173\u4e8e\u300aGo \u5207\u7247\u8f6c JSON \u4e3a\u7a7a\uff1a\u5982\u4f55\u89e3\u51b3\u5bfc\u51fa\u6210\u5458\u548c JSON \u7ed3\u6784\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff01,go \u5207\u7247\u8f6c json \u4e3a\u7a7a\u7684\u95ee\u9898\u89e3\u6790,\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u5207\u7247\u8f6c JSON \u4e3a\u7a7a\uff1a\u5982\u4f55\u89e3\u51b3\u5bfc\u51fa\u6210\u5458\u548c JSON \u7ed3\u6784\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728GOLANG\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\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>Go \u5207\u7247\u8f6c JSON \u4e3a\u7a7a\uff1a\u5982\u4f55\u89e3\u51b3\u5bfc\u51fa\u6210\u5458\u548c JSON \u7ed3\u6784\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f<\/span><\/p>\n<h1>Go \u5207\u7247\u8f6c JSON \u4e3a\u7a7a\uff1a\u5982\u4f55\u89e3\u51b3\u5bfc\u51fa\u6210\u5458\u548c JSON \u7ed3\u6784\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f<\/h1>\n<p><span>2024-11-21 21:49:17<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGo \u5207\u7247\u8f6c JSON \u4e3a\u7a7a\uff1a\u5982\u4f55\u89e3\u51b3\u5bfc\u51fa\u6210\u5458\u548c JSON \u7ed3\u6784\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728GOLANG\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732196941673f3a4d3d509.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>go \u5207\u7247\u8f6c json \u4e3a\u7a7a\u7684\u95ee\u9898\u89e3\u6790<\/strong><\/p>\n<p>\u5728 go \u8bed\u8a00\u4e2d\uff0c\u5207\u7247\u8f6c json \u9047\u5230\u7a7a\u6570\u7ec4\u7684\u95ee\u9898\uff0c\u53ef\u80fd\u6e90\u81ea\u4ee5\u4e0b\u539f\u56e0\uff1a<\/p>\n<p><strong>\u5bfc\u51fa\u6210\u5458\u548c json \u7ed3\u6784\u4e0d\u7b26<\/strong><\/p>\n<p>go \u53ea\u4f1a\u5e8f\u5217\u5316\u5bfc\u51fa\uff08\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\uff09\u7ed3\u6784\u6210\u5458\u3002\u5982\u679c\u5207\u7247\u5143\u7d20\u7c7b\u578b\u4e2d\u7684\u6210\u5458\u662f\u5c0f\u5199\u5f00\u5934\u7684\uff0c\u5219\u8fd9\u4e9b\u6210\u5458\u5c06\u4e0d\u4f1a\u5305\u542b\u5728 json \u8868\u793a\u4e2d\uff0c\u5bfc\u81f4\u7a7a\u6570\u7ec4\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u4fee\u6539\u7ed3\u6784\u4f53\u7684\u6210\u5458\u540d\u79f0\uff0c\u4f7f\u5176\u9996\u5b57\u6bcd\u5927\u5199\u3002<\/p>\n<pre>type user struct {\n    name string \/\/ \u5bfc\u51fa\u6210\u5458\uff0c\u5927\u5199\u5b57\u6bcd\u5f00\u5934\n    sfz  string `json:\"sfz\"` \/\/ \u52a0 json struct tag \u6307\u5b9a json \u4e2d\u7684\u540d\u79f0\n}<\/pre>\n<p><strong>json struct tag \u6307\u5b9a\u4e0d\u5f53<\/strong><\/p>\n<p>json struct tag \u53ef\u4ee5\u6307\u5b9a json \u4e2d\u7684\u540d\u79f0\u3002\u5982\u679c\u6307\u5b9a\u7684\u540d\u79f0\u4e0d\u5b58\u5728\uff0c\u5219\u8be5\u6210\u5458\u5c06\u88ab\u5ffd\u7565\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u4e2d\u7684 sfz \u6210\u5458\u4f7f\u7528\u4e86 json struct tag \u6307\u5b9a\u4e86\u4e0d\u540c\u7684 json \u540d\u79f0\uff0c\u4f46\u8be5\u540d\u79f0\u4e0d\u5b58\u5728\uff0c\u5bfc\u81f4\u8be5\u6210\u5458\u88ab\u5ffd\u7565\uff0c\u5207\u7247\u8f6c json \u540e\u4e3a\u7a7a\u3002<\/p>\n<pre>type user struct {\n    name string\n    sfz  string `json:\"sff\"` \/\/ \u4e0d\u5b58\u5728\u7684 json \u540d\u79f0\n}<\/pre>\n<p>\u4fee\u6539 json struct tag\uff0c\u4f7f\u7528\u6b63\u786e\u7684\u540d\u79f0\u5373\u53ef\u3002<\/p>\n<pre>type User struct {\n    name string\n    sfz  string `json:\"sfz\"` \/\/ \u6b63\u786e\u7684 JSON \u540d\u79f0\n}<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aGo \u5207\u7247\u8f6c JSON \u4e3a\u7a7a\uff1a\u5982\u4f55\u89e3\u51b3\u5bfc\u51fa\u6210\u5458\u548c JSON \u7ed3\u6784\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u9009\u62e9\u9002\u5408\u81ea\u5df1\u7684\u7b14\u8bb0\u672c\u7535\u8111\uff1a\u5168\u9762\u6307\u5357\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5c0f\u5929\u9e45e30\u6545\u969c\u4fee\u7535\u8111\u677f\uff0c\u5982\u4f55\u5feb\u901f\u89e3\u51b3\u95ee\u9898\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587 \u300a&#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-206753","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206753","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=206753"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206753\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}