{"id":41635,"date":"2024-12-01T12:58:05","date_gmt":"2024-12-01T04:58:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/41635\/"},"modified":"2024-12-01T12:58:05","modified_gmt":"2024-12-01T04:58:05","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e6%95%b0%e7%bb%84%e7%bc%96%e7%a0%81%e4%b8%ba-json-%e5%ad%97%e6%ae%b5%e7%9a%84%e5%80%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/41635\/","title":{"rendered":"\u5982\u4f55\u5c06\u6570\u7ec4\u7f16\u7801\u4e3a JSON \u5b57\u6bb5\u7684\u503c\uff1f"},"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>\u5982\u4f55\u5c06\u6570\u7ec4\u7f16\u7801\u4e3a JSON \u5b57\u6bb5\u7684\u503c\uff1f<\/span><\/p>\n<h1>\u5982\u4f55\u5c06\u6570\u7ec4\u7f16\u7801\u4e3a JSON \u5b57\u6bb5\u7684\u503c\uff1f<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-20 21:54:29<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60Golang\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u5982\u4f55\u5c06\u6570\u7ec4\u7f16\u7801\u4e3a JSON \u5b57\u6bb5\u7684\u503c\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u521a\u5f00\u59cb\u5b66\u4e60golang\uff0c\u6211\u6709\u4e00\u4e2a\u95ee\u9898\uff1a\u5982\u4f55\u5c06\u6570\u7ec4\u653e\u5165\u5bf9\u8c61\uff08\u7ed3\u6784\u4f53\uff09\u4e2d\uff0c\u4ee5\u4fbf\u5728json\u4e2d\u89e3\u6790\u65f6\u770b\u8d77\u6765\u50cf\u8fd9\u6837\uff1a<\/p>\n<pre>{\n\"key\":\"value\",\n\"array\": [1, 2, 3, \"num\", null]\n}<\/pre>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u53ea\u9700\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u9002\u5f53\u6570\u636e\u7c7b\u578b\u7684\u7ed3\u6784\u5e76\u5c06\u5176\u89e3\u7ec4\u5373\u53ef\uff1a<\/p>\n<\/p>\n<pre>type MyStruct struct {\n    Key string `json:\"key\"`\n    Array []interface{} `json:\"array\"`\n}\nbyt := []byte(`{\n    \"key\":\"value\",\n    \"array\": [1, 2, 3, \"num\", null]\n}`)\ndat := MyStruct{}\nif err := json.Unmarshal(byt, &amp;dat); err != nil {\n    panic(err)\n}\nfmt.Println(dat)<\/pre>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u5c06\u6570\u7ec4\u7f16\u7801\u4e3a JSON \u5b57\u6bb5\u7684\u503c\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5982\u4f55\u5c06\u6570\u7ec4\u7f16\u7801\u4e3a JSON \u5b57\u6bb5\u7684\u503c\uff1f \u5982\u4f55\u5c06\u6570\u7ec4\u7f16\u7801\u4e3a JSON \u5b57\u6bb5\u7684\u503c\uff1f \u6765\u6e90\uff1astackoverflow 2024-04-20 21:54:29 0\u6d4f\u89c8 \u6536\u85cf \u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60Golang\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u5982\u4f55\u5c06\u6570\u7ec4\u7f16\u7801\u4e3a JSON \u5b57\u6bb5\u7684\u503c\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u521a\u5f00\u59cb\u5b66\u4e60golang\uff0c\u6211\u6709\u4e00\u4e2a\u95ee\u9898\uff1a\u5982\u4f55\u5c06\u6570\u7ec4\u653e\u5165\u5bf9\u8c61\uff08\u7ed3\u6784\u4f53\uff09\u4e2d\uff0c\u4ee5\u4fbf\u5728json\u4e2d\u89e3\u6790\u65f6\u770b\u8d77\u6765\u50cf\u8fd9\u6837\uff1a { &#8220;key&#8221;:&#8221;value&#8221;, &#8220;array&#8221;: [1, 2, 3, &#8220;num&#8221;, null] } \u6b63\u786e\u7b54\u6848 \u53ea\u9700\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u9002\u5f53\u6570\u636e\u7c7b\u578b\u7684\u7ed3\u6784\u5e76\u5c06\u5176\u89e3\u7ec4\u5373\u53ef\uff1a type MyStruct struct { Key string `json:&#8221;key&#8221;` Array []interface{} `json:&#8221;array&#8221;` } byt := []byte(`{ &#8220;key&#8221;:&#8221;value&#8221;, &#8220;array&#8221;: [1, 2, 3, &#8220;num&#8221;, null] }`) dat [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-41635","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41635","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=41635"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41635\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=41635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=41635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=41635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}