{"id":42663,"date":"2024-12-01T12:51:57","date_gmt":"2024-12-01T04:51:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42663\/"},"modified":"2024-12-01T12:51:57","modified_gmt":"2024-12-01T04:51:57","slug":"%e8%a7%a3%e7%bb%84-json-%e6%97%b6%e4%b8%8d%e6%89%93%e5%8d%b0-stuct-%e4%b8%ad%e7%9a%84%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42663\/","title":{"rendered":"\u89e3\u7ec4 JSON \u65f6\u4e0d\u6253\u5370 Stuct \u4e2d\u7684\u503c"},"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\u7ec4 JSON \u65f6\u4e0d\u6253\u5370 Stuct \u4e2d\u7684\u503c<\/span><\/p>\n<h1>\u89e3\u7ec4 JSON \u65f6\u4e0d\u6253\u5370 Stuct \u4e2d\u7684\u503c<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-25 08:09:32<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u89e3\u7ec4 JSON \u65f6\u4e0d\u6253\u5370 Stuct \u4e2d\u7684\u503c\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u901a\u8fc7\u8c03\u7528 slack \u7684 api \u6765\u83b7\u53d6\u5176\u63d0\u9192\u5217\u8868\u3002\u6211\u9700\u8981\u4ece\u54cd\u5e94\u4e2d\u63d0\u53d6\u65f6\u95f4\u6233\u548c\u7528\u6237 id\u3002\u4f46\u5728\u89e3\u7ec4 json \u65f6\uff0c\u6211\u65e0\u6cd5\u5c06\u503c\u590d\u5236\u5230\u7ed3\u6784\u4e2d\u3002<\/p>\n<pre>package main\n\nimport (\n    \"encoding\/json\"\n    \"fmt\"\n    \"io\/ioutil\"\n    \"log\"\n    \"net\/http\"\n    \"time\"\n)\n\ntype ReadingHttpResponse struct {\n    ID         string    `json:\"id\"`\n    Creator    string    `json:\"creator\"`\n    User       string    `json:\"user\"`\n    Text       string    `json:\"text\"`\n    Recurring  bool      `json:\"recurring\"`\n    Time       time.Time `json:\"time\"`\n    CompleteTS int       `json:\"complete_ts\"`\n}\n\nfunc main() {\n\nurl := \"https:\/\/slack.com\/api\/reminders.list\"\n    var bearer = \"Bearer \" + \"My Bearer token\"\n    req, err := http.NewRequest(\"GET\", url, nil)\n    req.Header.Add(\"Authorization\", bearer)\n    client := &amp;http.Client{}\n    resp, err := client.Do(req)\n    if err != nil {\n        log.Println(\"Error on response.\\n[ERRO] -\", err)\n    }\n\n    body, err := ioutil.ReadAll(resp.Body)\n\n    if err != nil {\n        fmt.Println(err)\n    }\n\n    var m ReadingHttpResponse\n\n    err = json.Unmarshal(body, &amp;m)\n\n    if err != nil {\n        fmt.Println(err)\n    }\n\n   fmt.Printf(\"%#v\\r\\n\", m)\n\n}<\/pre>\n<h2>api \u54cd\u5e94\u7684 json \u4e3a<\/h2>\n<p> &#8220;ok&#8221;:true,&#8221;reminders&#8221;:[{&#8220;id&#8221;:&#8221;bacsasdad&#8221;,&#8221;creator&#8221;:&#8221;asdasdww&#8221;,&#8221;user&#8221;:&#8221;asdasdad&#8221;,&#8221;text&#8221;:&#8221;\u60a8\u597d\uff0c\u8fd9\u4ec5\u7528\u4e8e\u6d4b\u8bd5\u76ee\u7684&#8221;, \u201c\u91cd\u590d\u201d\uff1a\u5047\uff0c\u201c\u65f6\u95f4\u201d\uff1a1578470823\uff0c\u201ccomplete_ts\u201d\uff1a0}]} <\/p>\n<h2>\u4f46\u662f unmarshaled \u6570\u636e\u6ca1\u6709\u503c<\/h2>\n<p>main.readinghttpresponse{id:&#8221;&#8221;, \u521b\u5efa\u8005:&#8221;&#8221;, \u7528\u6237:&#8221;&#8221;, \u6587\u672c:&#8221;&#8221;, \u91cd\u590d:false, \u65f6\u95f4:time.time{wall:0x0, ext:0, loc:(*time .\u4f4d\u7f6e)(nil)}\uff0c\u5b8c\u6574ts\uff1a0}<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u7684\u7ed3\u6784\u4e0e json \u54cd\u5e94\u4e0d\u5bf9\u5e94\uff0c\u5b83\u5e94\u8be5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre>\ntype ReadingHttpResponse struct {\n    Ok        bool `json:\"ok\"`\n    Reminders []Reminder `json:\"reminders\"`\n}\n\ntype Reminder struct {\n        ID         string `json:\"id\"`\n        Creator    string `json:\"creator\"`\n        User       string `json:\"user\"`\n        Text       string `json:\"text\"`\n        Recurring  bool   `json:\"recurring\"`\n        Time       int    `json:\"time\"`\n        CompleteTs int    `json:\"complete_ts\"`\n} \n\n<\/pre>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u89e3\u7ec4 JSON \u65f6\u4e0d\u6253\u5370 Stuct \u4e2d\u7684\u503c\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; \u89e3\u7ec4 JSON \u65f6\u4e0d\u6253\u5370 Stuct \u4e2d\u7684\u503c \u89e3\u7ec4 JSON \u65f6\u4e0d\u6253\u5370 Stuct \u4e2d\u7684\u503c \u6765\u6e90\uff1astackoverflow 2024-04-25 08:09:32 0\u6d4f\u89c8 \u6536\u85cf \u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u300a\u89e3\u7ec4 JSON \u65f6\u4e0d\u6253\u5370 Stuct \u4e2d\u7684\u503c\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u6b63\u5728\u5c1d\u8bd5\u901a\u8fc7\u8c03\u7528 slack \u7684 api \u6765\u83b7\u53d6\u5176\u63d0\u9192\u5217\u8868\u3002\u6211\u9700\u8981\u4ece\u54cd\u5e94\u4e2d\u63d0\u53d6\u65f6\u95f4\u6233\u548c\u7528\u6237 id\u3002\u4f46\u5728\u89e3\u7ec4 json \u65f6\uff0c\u6211\u65e0\u6cd5\u5c06\u503c\u590d\u5236\u5230\u7ed3\u6784\u4e2d\u3002 package main import ( &#8220;encoding\/json&#8221; &#8220;fmt&#8221; &#8220;io\/ioutil&#8221; &#8220;log&#8221; &#8220;net\/http&#8221; &#8220;time&#8221; ) type ReadingHttpResponse struct { ID string `json:&#8221;id&#8221;` Creator string `json:&#8221;creator&#8221;` [&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-42663","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42663","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=42663"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42663\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}