{"id":206040,"date":"2025-06-12T09:32:10","date_gmt":"2025-06-12T01:32:10","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206040\/"},"modified":"2025-06-12T09:32:10","modified_gmt":"2025-06-12T01:32:10","slug":"golang-json-%e8%a7%a3%e6%9e%90%e9%9a%be%e9%a2%98%ef%bc%9a%e5%a6%82%e4%bd%95%e5%b0%86%e4%b8%80%e7%bb%84%e5%ad%97%e8%8a%82%e6%95%b0%e7%bb%84%e8%a7%a3%e6%9e%90%e6%88%90%e7%bb%93%e6%9e%84%e4%bd%93","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206040\/","title":{"rendered":"Golang JSON \u89e3\u6790\u96be\u9898\uff1a\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\uff1f"},"content":{"rendered":"<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aGOLANG JSON \u89e3\u6790\u96be\u9898\uff1a\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241101\/17304537816724a11542764.jpg\" class=\"aligncenter\">,<br \/>\n<strong>golang json \u89e3\u6790\u96be\u9898<\/strong>,\u5728 json \u6570\u636e\u89e3\u6790\u8fc7\u7a0b\u4e2d\uff0c\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\u65f6\uff0c\u65b0\u624b\u5e38\u5e38\u4f1a\u9047\u5230\u56f0\u96be\u3002,\u95ee\u9898\u63cf\u8ff0\uff1a,\u6267\u884c\u4ee3\u7801\u4f1a\u62a5\u9519\uff1a,<br \/>\n<strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>,\u5728 go \u4e2d\u89e3\u6790 json \u6570\u636e\u65f6\uff0c\u9700\u8981\u660e\u786e\u6307\u5b9a\u7ed3\u6784\u4f53\u7684\u5b8c\u6574\u7ed3\u6784\u3002\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a,\u8bf7\u6ce8\u610f\uff0c\u5728 go \u4e2d\u4ece\u5b57\u7b26\u4e32\u89e3\u6790\u51fa\u7ed3\u6784\u4f53\u65f6\uff0c\u9700\u8981\u5199\u660e\u6240\u6709\u7ed3\u6784\u4f53\u7ed3\u6784\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u89e3\u6790\u9519\u8bef\u3002,\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aGOLANG JSON \u89e3\u6790\u96be\u9898\uff1a\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~GOLANG\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03GOLANG\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01,golang json \u89e3\u6790\u96be\u9898,\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aGOLANG JSON \u89e3\u6790\u96be\u9898\uff1a\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002,<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 \u89e3\u6790\u96be\u9898\uff1a\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\uff1f<\/span><\/p>\n<h1>GOLANG JSON \u89e3\u6790\u96be\u9898\uff1a\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\uff1f<\/h1>\n<p><span>2024-11-01 17:36:36<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aGOLANG JSON \u89e3\u6790\u96be\u9898\uff1a\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241101\/17304537816724a11542764.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>golang json \u89e3\u6790\u96be\u9898<\/strong><\/p>\n<p>\u5728 json \u6570\u636e\u89e3\u6790\u8fc7\u7a0b\u4e2d\uff0c\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\u65f6\uff0c\u65b0\u624b\u5e38\u5e38\u4f1a\u9047\u5230\u56f0\u96be\u3002<\/p>\n<p>\u95ee\u9898\u63cf\u8ff0\uff1a<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n\n    jsoniter \"github.com\/json-iterator\/go\"\n)\n\ntype car struct {\n    other []byte `json:\"other\"`\n}\n\nfunc main() {\n    j := []byte(`{\"other\": {\"a\":[1,2]}}`)\n    json := jsoniter.configcompatiblewithstandardlibrary\n    obj := car{}\n    err := json.unmarshal(j, &amp;obj)\n    if err != nil {\n        fmt.println(err.error())\n    } else {\n        fmt.println(obj)\n    }\n}<\/pre>\n<p>\u6267\u884c\u4ee3\u7801\u4f1a\u62a5\u9519\uff1a<\/p>\n<pre>main.car.other: base64codec: invalid input, error found in #10 byte of ...|{\"other\": {\"a\":[1,2]|..., bigger context ...|{\"other\": {\"a\":[1,2]}}|...<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u5728 go \u4e2d\u89e3\u6790 json \u6570\u636e\u65f6\uff0c\u9700\u8981\u660e\u786e\u6307\u5b9a\u7ed3\u6784\u4f53\u7684\u5b8c\u6574\u7ed3\u6784\u3002\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n\n    jsoniter \"github.com\/json-iterator\/go\"\n)\n\ntype other struct {\n    A []int `json:\"a,omitempty\"`\n}\n\n\/\/ Car \u8f66\ntype Car struct {\n    Other other `json:\"other,omitempty\"`\n}\n\nfunc main() {\n    j := []byte(`{\"other\": {\"a\":[1,2]}}`)\n    json := jsoniter.ConfigCompatibleWithStandardLibrary\n    obj := Car{}\n    err := json.Unmarshal(j, &amp;obj)\n    if err != nil {\n        fmt.Println(err.Error())\n    } else {\n        fmt.Printf(\"%+v\\n\", obj)\n    }\n}<\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u5728 go \u4e2d\u4ece\u5b57\u7b26\u4e32\u89e3\u6790\u51fa\u7ed3\u6784\u4f53\u65f6\uff0c\u9700\u8981\u5199\u660e\u6240\u6709\u7ed3\u6784\u4f53\u7ed3\u6784\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u89e3\u6790\u9519\u8bef\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aGOLANG JSON \u89e3\u6790\u96be\u9898\uff1a\u5982\u4f55\u5c06\u4e00\u7ec4\u5b57\u8282\u6570\u7ec4\u89e3\u6790\u6210\u7ed3\u6784\u4f53\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~GOLANG\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03GOLANG\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u8bc6\u522b\u4e0d\u540c\u6d4f\u89c8\u5668\u5e76\u89e3\u51b3\u7f51\u9875\u5f00\u53d1\u4e2d\u7684\u5e38\u89c1\u95ee\u9898\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u7b80\u5355\u6613\u5b66\u7684\u7535\u8111\u7b80\u7b14\u753b\u6559\u7a0b\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00&#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-206040","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206040","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=206040"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206040\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}