{"id":42133,"date":"2024-12-01T11:49:51","date_gmt":"2024-12-01T03:49:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42133\/"},"modified":"2024-12-01T11:49:51","modified_gmt":"2024-12-01T03:49:51","slug":"%e8%a7%a3%e6%9e%90%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%8f%91%e9%80%81%e7%9a%84%e6%95%b0%e7%bb%84-%e5%88%87%e7%89%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42133\/","title":{"rendered":"\u89e3\u6790\u670d\u52a1\u5668\u53d1\u9001\u7684\u6570\u7ec4\/\u5207\u7247"},"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>\u89e3\u6790\u670d\u52a1\u5668\u53d1\u9001\u7684\u6570\u7ec4\/\u5207\u7247<\/span><\/p>\n<h1>\u89e3\u6790\u670d\u52a1\u5668\u53d1\u9001\u7684\u6570\u7ec4\/\u5207\u7247<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-22 19:15:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u89e3\u6790\u670d\u52a1\u5668\u53d1\u9001\u7684\u6570\u7ec4\/\u5207\u7247\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u670d\u52a1\u5668\u6b63\u5728\u53d1\u56de\u8fd9\u6837\u7684\u54cd\u5e94\uff1a<\/p>\n<pre>me@linux:~&gt; curl -x get http:\/\/*.*.*.*:8080\/profiles\n\n[\n        {\n                \"profileid\": 1,\n                \"title\": \"65micron\"\n        },\n        {\n                \"profileid\": 2,\n                \"title\": \"80micron\"\n        }\n]<\/pre>\n<p>\u6211\u5c1d\u8bd5\u8fc7\u6b64\u89e3\u51b3\u65b9\u6848\u5c06\u54cd\u5e94\u89e3\u6790\u4e3a json\uff0c\u4f46\u5b83<strong>\u4ec5<\/strong>\u5728\u670d\u52a1\u5668\u54cd\u5e94\u5982\u4e0b\u6240\u793a\u65f6\u6709\u6548\uff1a<\/p>\n<pre>{\n    \"array\": [\n        {\n                \"ProfileID\": 1,\n                \"Title\": \"65micron\"\n        },\n        {\n                \"ProfileID\": 2,\n                \"Title\": \"80micron\"\n        }\n    ]\n}<\/pre>\n<p>\u6709\u4eba\u77e5\u9053\u5982\u4f55\u5c06\u670d\u52a1\u5668\u54cd\u5e94\u89e3\u6790\u4e3a json \u5417\uff1f<\/p>\n<p>\u6211\u60f3\u5230\u7684\u4e00\u4e2a\u60f3\u6cd5\u662f\u5c06 <code>{ \"array\":<\/code> \u6dfb\u52a0\u5230 <code>http.response.body<\/code> \u7f13\u51b2\u533a\u7684\u5f00\u5934\uff0c\u5e76\u5c06 <code>}<\/code> \u6dfb\u52a0\u5230\u5176\u672b\u5c3e\uff0c\u7136\u540e\u4f7f\u7528\u6807\u51c6\u89e3\u51b3\u65b9\u6848\u3002\u4f46\u662f\uff0c\u6211\u4e0d\u786e\u5b9a\u8fd9\u662f\u5426\u662f\u6700\u597d\u7684\u4e3b\u610f\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u53ef\u4ee5\u76f4\u63a5\u89e3\u7ec4\u5230\u6570\u7ec4\u4e2d<\/p>\n<pre>data := `[\n    {\n        \"profileid\": 1,\n        \"title\": \"65micron\"\n    },\n    {\n        \"profileid\": 2,\n        \"title\": \"80micron\"\n    }]`\n\ntype profile struct {\n    profileid int\n    title     string\n}\n\nvar profiles []profile\n\njson.unmarshal([]byte(data), &amp;profiles)<\/pre>\n<p>\u60a8\u8fd8\u53ef\u4ee5\u76f4\u63a5\u4ece <code>request.body<\/code> \u8bfb\u53d6\u3002<\/p>\n<pre>func handler(w http.responsewriter, r *http.request) {\n\n    var profiles []profile\n    json.newdecoder(r.body).decode(&amp;profiles)\n    \/\/ use `profiles`\n}<\/pre>\n<\/p>\n<p>\u60a8\u5e94\u8be5\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53<\/p>\n<pre>type profile struct {\n    id int `json:\"profileid\"`\n    title string `json:\"title\"`\n}<\/pre>\n<p>\u89e3\u7801\u54cd\u5e94\u4e4b\u540e<\/p>\n<pre>var r []Profile\nerr := json.NewDecoder(res.Body).Decode(&amp;r)<\/pre>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300a\u89e3\u6790\u670d\u52a1\u5668\u53d1\u9001\u7684\u6570\u7ec4\/\u5207\u7247\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u89e3\u6790\u670d\u52a1\u5668\u53d1\u9001\u7684\u6570\u7ec4\/\u5207\u7247 \u89e3\u6790\u670d\u52a1\u5668\u53d1\u9001\u7684\u6570\u7ec4\/\u5207\u7247 \u6765\u6e90\uff1astackoverflow 2024-04-22 19:15:35 0\u6d4f\u89c8 \u6536\u85cf \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7\u300a\u89e3\u6790\u670d\u52a1\u5668\u53d1\u9001\u7684\u6570\u7ec4\/\u5207\u7247\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0Golang\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01 \u95ee\u9898\u5185\u5bb9 \u670d\u52a1\u5668\u6b63\u5728\u53d1\u56de\u8fd9\u6837\u7684\u54cd\u5e94\uff1a me@linux:~&gt; curl -x get http:\/\/*.*.*.*:8080\/profiles [ { &#8220;profileid&#8221;: 1, &#8220;title&#8221;: &#8220;65micron&#8221; }, { &#8220;profileid&#8221;: 2, &#8220;title&#8221;: &#8220;80micron&#8221; } ] \u6211\u5c1d\u8bd5\u8fc7\u6b64\u89e3\u51b3\u65b9\u6848\u5c06\u54cd\u5e94\u89e3\u6790\u4e3a json\uff0c\u4f46\u5b83\u4ec5\u5728\u670d\u52a1\u5668\u54cd\u5e94\u5982\u4e0b\u6240\u793a\u65f6\u6709\u6548\uff1a { &#8220;array&#8221;: [ { &#8220;ProfileID&#8221;: 1, &#8220;Title&#8221;: &#8220;65micron&#8221; }, { &#8220;ProfileID&#8221;: 2, &#8220;Title&#8221;: &#8220;80micron&#8221; } ] } \u6709\u4eba\u77e5\u9053\u5982\u4f55\u5c06\u670d\u52a1\u5668\u54cd\u5e94\u89e3\u6790\u4e3a json [&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-42133","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42133","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=42133"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42133\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}