{"id":205929,"date":"2025-06-12T08:43:19","date_gmt":"2025-06-12T00:43:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205929\/"},"modified":"2025-06-12T08:43:19","modified_gmt":"2025-06-12T00:43:19","slug":"golang-json-%e5%8c%96%e4%b8%ad%e9%87%8d%e5%86%99-unmarshaljson-%e5%90%8e%e4%b8%ba%e4%bd%95%e5%8f%96%e4%b8%8d%e5%88%b0%e5%80%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205929\/","title":{"rendered":"Golang JSON \u5316\u4e2d\u91cd\u5199 UnmarshalJSON \u540e\u4e3a\u4f55\u53d6\u4e0d\u5230\u503c\uff1f"},"content":{"rendered":"<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGOLANG JSON \u5316\u4e2d\u91cd\u5199 UnmarshalJSON \u540e\u4e3a\u4f55\u53d6\u4e0d\u5230\u503c\uff1f\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span>,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730093962671f238adb0b1.jpg\" class=\"aligncenter\">,<br \/>\n<strong>golang json \u5316\u4e2d\u91cd\u5199 unmarshaljson \u540e\u53d6\u4e0d\u5230\u503c<\/strong>,\u5728 golang \u4e2d\u4f7f\u7528 json \u53cd\u5e8f\u5217\u5316\u65f6\u91cd\u5199\u7ed3\u6784\u4f53\u6216\u5d4c\u5957\u7ed3\u6784\u4f53\u4e2d\u7684 unmarshaljson \u65b9\u6cd5\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u53d6\u4e0d\u5230\u503c\u3002,<br \/>\n<strong>\u95ee\u9898\u539f\u56e0\uff1a<\/strong>,\u5f53\u91cd\u5199\u533f\u540d\u5d4c\u5957\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5\u65f6\uff0c\u5916\u90e8\u7ed3\u6784\u4f53\u4e5f\u4f1a\u7ee7\u627f\u8be5\u65b9\u6cd5\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5916\u90e8\u7ed3\u6784\u4f53\u5728\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u65f6\u5c06\u76f4\u63a5\u8c03\u7528\u8be5\u91cd\u5199\u7684 unmarshaljson \u65b9\u6cd5\uff0c\u800c\u5ffd\u7565\u5176\u6210\u5458\u53d8\u91cf\u7684\u81ea\u5b9a\u4e49\u53cd\u5e8f\u5217\u5316\u903b\u8f91\u3002,<br \/>\n<strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>,<br \/>\n<strong>\u793a\u4f8b\uff1a\u91cd\u5199\u5916\u90e8\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5<\/strong>,\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301GOLANG\uff01\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u3002,<br \/>\n<strong>\u91cd\u5199\u5916\u90e8\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5\uff1a<\/strong> \u76f4\u63a5\u91cd\u5199\u5916\u90e8\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5\uff0c\u5b9e\u73b0\u6240\u6709\u5d4c\u5957\u7ed3\u6784\u4f53\u7684\u81ea\u5b9a\u4e49\u53cd\u5e8f\u5217\u5316\u903b\u8f91\u3002,<br \/>\n<strong>\u6309\u7167\u6700\u5c0f\u7c92\u5ea6\u91cd\u5199\u65b9\u6cd5\uff1a<\/strong> \u53ea\u91cd\u5199\u9700\u8981\u81ea\u5b9a\u4e49\u53cd\u5e8f\u5217\u5316\u7684\u7ed3\u6784\u4f53\u6216\u5d4c\u5957\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5\u3002,<br \/>\n<strong>\u4fee\u6539\u7ed3\u6784\u4f53\u5b9a\u4e49\uff1a<\/strong> \u907f\u514d\u533f\u540d\u5d4c\u5957\u7ed3\u6784\u4f53\uff0c\u800c\u662f\u5c06\u5d4c\u5957\u7ed3\u6784\u4f53\u4f5c\u4e3a\u5916\u90e8\u7ed3\u6784\u4f53\u7684\u6210\u5458\u53d8\u91cf\u5b9a\u4e49\u3002,golang json \u5316\u4e2d\u91cd\u5199 unmarshaljson \u540e\u53d6\u4e0d\u5230\u503c,<br \/>\n<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGOLANG JSON \u5316\u4e2d\u91cd\u5199 UnmarshalJSON \u540e\u4e3a\u4f55\u53d6\u4e0d\u5230\u503c\uff1f\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span>,<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>GOLANG JSON \u5316\u4e2d\u91cd\u5199 UnmarshalJSON \u540e\u4e3a\u4f55\u53d6\u4e0d\u5230\u503c\uff1f<\/span><\/p>\n<h1>GOLANG JSON \u5316\u4e2d\u91cd\u5199 UnmarshalJSON \u540e\u4e3a\u4f55\u53d6\u4e0d\u5230\u503c\uff1f<\/h1>\n<p><span>2024-10-28 13:39:39<\/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=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGOLANG JSON \u5316\u4e2d\u91cd\u5199 UnmarshalJSON \u540e\u4e3a\u4f55\u53d6\u4e0d\u5230\u503c\uff1f\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730093962671f238adb0b1.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>golang json \u5316\u4e2d\u91cd\u5199 unmarshaljson \u540e\u53d6\u4e0d\u5230\u503c<\/strong><\/p>\n<p>\u5728 golang \u4e2d\u4f7f\u7528 json \u53cd\u5e8f\u5217\u5316\u65f6\u91cd\u5199\u7ed3\u6784\u4f53\u6216\u5d4c\u5957\u7ed3\u6784\u4f53\u4e2d\u7684 unmarshaljson \u65b9\u6cd5\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u53d6\u4e0d\u5230\u503c\u3002<\/p>\n<p><strong>\u95ee\u9898\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u5f53\u91cd\u5199\u533f\u540d\u5d4c\u5957\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5\u65f6\uff0c\u5916\u90e8\u7ed3\u6784\u4f53\u4e5f\u4f1a\u7ee7\u627f\u8be5\u65b9\u6cd5\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5916\u90e8\u7ed3\u6784\u4f53\u5728\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u65f6\u5c06\u76f4\u63a5\u8c03\u7528\u8be5\u91cd\u5199\u7684 unmarshaljson \u65b9\u6cd5\uff0c\u800c\u5ffd\u7565\u5176\u6210\u5458\u53d8\u91cf\u7684\u81ea\u5b9a\u4e49\u53cd\u5e8f\u5217\u5316\u903b\u8f91\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u6309\u7167\u6700\u5c0f\u7c92\u5ea6\u91cd\u5199\u65b9\u6cd5\uff1a<\/strong> \u53ea\u91cd\u5199\u9700\u8981\u81ea\u5b9a\u4e49\u53cd\u5e8f\u5217\u5316\u7684\u7ed3\u6784\u4f53\u6216\u5d4c\u5957\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5\u3002<\/li>\n<li><strong>\u91cd\u5199\u5916\u90e8\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5\uff1a<\/strong> \u76f4\u63a5\u91cd\u5199\u5916\u90e8\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5\uff0c\u5b9e\u73b0\u6240\u6709\u5d4c\u5957\u7ed3\u6784\u4f53\u7684\u81ea\u5b9a\u4e49\u53cd\u5e8f\u5217\u5316\u903b\u8f91\u3002<\/li>\n<li><strong>\u4fee\u6539\u7ed3\u6784\u4f53\u5b9a\u4e49\uff1a<\/strong> \u907f\u514d\u533f\u540d\u5d4c\u5957\u7ed3\u6784\u4f53\uff0c\u800c\u662f\u5c06\u5d4c\u5957\u7ed3\u6784\u4f53\u4f5c\u4e3a\u5916\u90e8\u7ed3\u6784\u4f53\u7684\u6210\u5458\u53d8\u91cf\u5b9a\u4e49\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a\u91cd\u5199\u5916\u90e8\u7ed3\u6784\u4f53\u7684 unmarshaljson \u65b9\u6cd5<\/strong><\/p>\n<pre>func (s *A) UnmarshalJSON(data []byte) error {\n    t := struct {\n        Ids []string `json:\"ids\"`\n        More string `json:\"more\"`\n    }{}\n\n    if err := json.Unmarshal(data, &amp;t); err != nil {\n        return err\n    }\n    for _, id := range t.Ids {\n        uId, err := strconv.ParseInt(id, 10, 64)\n        if err != nil {\n            return err\n        }\n        s.Ids = append(s.Ids, uint64(uId))\n    }\n    s.More = t.More\n    return nil\n}<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301GOLANG\uff01\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   Java\u51fd\u6570\u4e0e\u65b9\u6cd5\u7684\u533a\u522b\u4e0e\u8054\u7cfb\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   PyQt5 \u9047\u5230 \\&#8221;No module named \\&#8217;QtWidgets\\&#8217;\\&#8221; \u9519\u8bef \u5982\u4f55\u89e3\u51b3\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929&#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-205929","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205929","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=205929"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205929\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}