{"id":827,"date":"2024-11-07T11:10:06","date_gmt":"2024-11-07T03:10:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/827\/"},"modified":"2024-11-07T11:10:06","modified_gmt":"2024-11-07T03:10:06","slug":"golang-json-%e8%a7%a3%e6%9e%90%e9%97%ae%e9%a2%98%ef%bc%9a%e5%b5%8c%e5%a5%97%e7%bb%93%e6%9e%84%e9%87%8d%e5%86%99-unmarshaljson-%e5%90%8e%e4%b8%a2%e5%a4%b1%e5%80%bc%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/827\/","title":{"rendered":"Golang JSON \u89e3\u6790\u95ee\u9898\uff1a\u5d4c\u5957\u7ed3\u6784\u91cd\u5199 UnmarshalJSON \u540e\u4e22\u5931\u503c\u7684\u89e3\u51b3\u65b9\u6cd5\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1077\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172992997242264.jpg\" width=\"800\" height=\"320\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172992997242264.jpg 800w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172992997242264-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172992997242264-768x307.jpg 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172992997242264-670x268.jpg 670w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" title=\"Golang JSON \u89e3\u6790\u95ee\u9898\uff1a\u5d4c\u5957\u7ed3\u6784\u91cd\u5199 UnmarshalJSON \u540e\u4e22\u5931\u503c\u7684\u89e3\u51b3\u65b9\u6cd5\uff1f\u63d2\u56fe\" alt=\"Golang JSON \u89e3\u6790\u95ee\u9898\uff1a\u5d4c\u5957\u7ed3\u6784\u91cd\u5199 UnmarshalJSON \u540e\u4e22\u5931\u503c\u7684\u89e3\u51b3\u65b9\u6cd5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>Golang JSON \u89e3\u6790\u95ee\u9898\uff1a\u91cd\u5199 UnmarshalJSON \u540e\u4e22\u5931\u503c<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 Golang \u5904\u7406 JSON \u65f6\uff0c\u91cd\u5199\u4e86\u7ed3\u6784\u4f53\u7684 UnmarshalJSON \u65b9\u6cd5\uff0c\u5374\u65e0\u6cd5\u83b7\u5f97\u5b8c\u6574\u7684\u503c\u3002\u8ba9\u6211\u4eec\u6765\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e2a\u95ee\u9898\uff1a<\/p>\n<p><strong>\u539f\u56e0\uff1a\u7ed3\u6784\u4f53\u5d4c\u5957\u7ee7\u627f<\/strong><\/p>\n<p>\u5728 Golang \u4e2d\uff0c\u7ed3\u6784\u4f53\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5d4c\u5165\u7684\u65b9\u5f0f\u8fdb\u884c\u5d4c\u5957\u3002\u5f53\u7ed3\u6784\u4f53 A \u5d4c\u5957\u4e86\u7ed3\u6784\u4f53 B \u65f6\uff0cA \u5c06\u7ee7\u627f B \u7684\u63a5\u53e3\uff0c\u5305\u62ec UnmarshalJSON \u65b9\u6cd5\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cgo\u8bed\u8a00\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<p><strong>\u5206\u6790\u4ee3\u7801<\/strong><\/p>\n<p>\u5728\u4f60\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0cIdArr \u7ed3\u6784\u4f53\u533f\u540d\u5d4c\u5957\u5728 A \u7ed3\u6784\u4f53\u4e2d\u3002\u56e0\u6b64\uff0c\u5f53\u91cd\u5199 IdArr \u7684 UnmarshalJSON \u65b9\u6cd5\u65f6\uff0cA \u4e5f\u7ee7\u627f\u4e86\u8be5\u65b9\u6cd5\u3002\u8fd9\u4f1a\u5bfc\u81f4\u89e3\u6790 JSON \u5b57\u7b26\u4e32\u65f6\uff0c\u8c03\u7528\u7684\u662f A \u7684\u91cd\u5199\u65b9\u6cd5\uff0c\u800c\u8be5\u65b9\u6cd5\u53ea\u5904\u7406 IdArr \u90e8\u5206\uff0c\u5ffd\u7565\u4e86 more \u5b57\u6bb5\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u6709\u4ee5\u4e0b\u51e0\u79cd\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li> <strong>\u6700\u5c0f\u7c92\u5ea6\u91cd\u5199\u65b9\u6cd5\uff1a<\/strong>\u4f7f\u7528\u66f4\u5177\u4f53\u7684\u7ed3\u6784\u4e3a\u91cd\u5199\u65b9\u6cd5\u5b9a\u4e49\u7c7b\u578b\uff0c\u4ee5\u4fbf\u7cbe\u786e\u63a7\u5236\u89e3\u6790\u7684\u884c\u4e3a\u3002<\/li>\n<li> <strong>\u91cd\u5199 A \u7684 UnmarshalJSON \u65b9\u6cd5\uff1a<\/strong>\u907f\u514d\u91cd\u5199 IdArr \u7684 UnmarshalJSON \u65b9\u6cd5\uff0c\u800c\u76f4\u63a5\u91cd\u5199 A \u7684 UnmarshalJSON \u65b9\u6cd5\uff0c\u5904\u7406\u66f4\u5b8c\u6574\u7684 JSON \u5b57\u7b26\u4e32\u3002<\/li>\n<li> <strong>\u4fee\u6539\u7ed3\u6784\u4f53\u5b9a\u4e49\uff1a<\/strong>\u5982\u679c\u53ef\u80fd\uff0c\u5c06 IdArr \u5b9a\u4e49\u4e3a\u72ec\u7acb\u7684\u7ed3\u6784\u4f53\uff0c\u907f\u514d\u5d4c\u5957\uff0c\u79fb\u9664\u7ee7\u627f\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>Temp \u7ed3\u6784\u4f53\u5728\u4f60\u7684 UnmarshalJSON \u5b9e\u73b0\u4e2d\u6ca1\u6709\u5fc5\u8981\u3002<\/li>\n<li>\u4f60\u91cd\u5199 UnmarshalJSON \u65f6\u5904\u7406\u7684\u662f\u8f6c\u6362\u540e\u7684\u5b57\u7b26\u4e32\uff0c\u800c\u5e76\u975e\u539f\u59cb\u7684 JSON \u6570\u636e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fGolang JSON \u89e3\u6790\u95ee\u9898\uff1a\u5d4c\u5957\u7ed3\u6784\u91cd\u5199 UnmarshalJSON \u540e\u4e22\u5931\u503c\u7684\u89e3\u51b3\u65b9\u6cd5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Golang JSON \u89e3\u6790\u95ee\u9898\uff1a\u91cd\u5199 UnmarshalJSON \u540e\u4e22\u5931\u503c \u5728\u4f7f\u7528 Golang \u5904\u7406 JSON \u65f6\uff0c\u91cd\u5199\u4e86\u7ed3\u6784\u4f53\u7684 UnmarshalJSON \u65b9\u6cd5\uff0c\u5374\u65e0\u6cd5\u83b7\u5f97\u5b8c\u6574\u7684\u503c\u3002\u8ba9\u6211\u4eec\u6765\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e2a\u95ee\u9898\uff1a \u539f\u56e0\uff1a\u7ed3\u6784\u4f53\u5d4c\u5957\u7ee7\u627f \u5728 Golang \u4e2d\uff0c\u7ed3\u6784\u4f53\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5d4c\u5165\u7684\u65b9\u5f0f\u8fdb\u884c\u5d4c\u5957\u3002\u5f53\u7ed3\u6784\u4f53 A \u5d4c\u5957\u4e86\u7ed3\u6784\u4f53 B \u65f6\uff0cA \u5c06\u7ee7\u627f B \u7684\u63a5\u53e3\uff0c\u5305\u62ec UnmarshalJSON \u65b9\u6cd5\u3002 \u7acb\u5373\u5b66\u4e60\u201cgo\u8bed\u8a00\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b \u5206\u6790\u4ee3\u7801 \u5728\u4f60\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0cIdArr \u7ed3\u6784\u4f53\u533f\u540d\u5d4c\u5957\u5728 A \u7ed3\u6784\u4f53\u4e2d\u3002\u56e0\u6b64\uff0c\u5f53\u91cd\u5199 IdArr \u7684 UnmarshalJSON \u65b9\u6cd5\u65f6\uff0cA \u4e5f\u7ee7\u627f\u4e86\u8be5\u65b9\u6cd5\u3002\u8fd9\u4f1a\u5bfc\u81f4\u89e3\u6790 JSON \u5b57\u7b26\u4e32\u65f6\uff0c\u8c03\u7528\u7684\u662f A \u7684\u91cd\u5199\u65b9\u6cd5\uff0c\u800c\u8be5\u65b9\u6cd5\u53ea\u5904\u7406 IdArr \u90e8\u5206\uff0c\u5ffd\u7565\u4e86 more \u5b57\u6bb5\u3002 \u89e3\u51b3\u65b9\u6cd5 \u6709\u4ee5\u4e0b\u51e0\u79cd\u89e3\u51b3\u65b9\u6cd5\uff1a \u6700\u5c0f\u7c92\u5ea6\u91cd\u5199\u65b9\u6cd5\uff1a\u4f7f\u7528\u66f4\u5177\u4f53\u7684\u7ed3\u6784\u4e3a\u91cd\u5199\u65b9\u6cd5\u5b9a\u4e49\u7c7b\u578b\uff0c\u4ee5\u4fbf\u7cbe\u786e\u63a7\u5236\u89e3\u6790\u7684\u884c\u4e3a\u3002 \u91cd\u5199 A \u7684 UnmarshalJSON \u65b9\u6cd5\uff1a\u907f\u514d\u91cd\u5199 IdArr \u7684 UnmarshalJSON [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-827","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}