{"id":277704,"date":"2021-01-13T16:14:36","date_gmt":"2021-01-13T08:14:36","guid":{"rendered":"http:\/\/4563.org\/?p=277704"},"modified":"2021-01-13T16:14:36","modified_gmt":"2021-01-13T08:14:36","slug":"%e8%af%b7%e6%95%99%ef%bc%9a%e8%bf%9c%e7%a8%8b-get-%e5%88%b0%e5%a4%8d%e6%9d%82-json-%e6%9e%81%e5%b0%91%e4%bf%ae%e6%94%b9%e4%b9%8b%e5%90%8e%e4%bc%a0%e7%bb%99%e5%89%8d%e7%ab%af%e7%94%a8%ef%bc%8c%e6%80%8e","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=277704","title":{"rendered":"\u8bf7\u6559\uff1a\u8fdc\u7a0b Get \u5230\u590d\u6742 JSON \u6781\u5c11\u4fee\u6539\u4e4b\u540e\u4f20\u7ed9\u524d\u7aef\u7528\uff0c\u600e\u4e48\u505a\u6700\u5feb\u6377\u9ad8\u6548\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\uff1a\u8fdc\u7a0b Get \u5230\u590d\u6742 JSON \u6781\u5c11\u4fee\u6539\u4e4b\u540e\u4f20\u7ed9\u524d\u7aef\u7528\uff0c\u600e\u4e48\u505a\u6700\u5feb\u6377\u9ad8\u6548\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dimlau <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>func GetWM(w http.ResponseWriter, r *http.Request) {  \/\/\u4e00\u5199\u4ee3\u7801 \/\/\u7701\u7565\u6389\u4e86 \/\/var TOTID \/\/r.Method == \"GET\"   w.Header().Set(\"Content-Type\", \"application\/json\")  resp, err := http.Get(\"\/\/\/xxxxx.json\")  if err != nil {   panic(err)  }  defer resp.Body.Close()  body, _ :=ioutil.ReadAll(resp.Body)  addthis := fmt.Sprintf(`{\"id\":\"%s\",`,TOTID)  body = append([]byte(addthis),body[1:]...)  b=string(body)  fmt.Fprint(w, b) } <\/code><\/pre>\n<p>\u8fd9\u6837\u5199\u662f\u4e0d\u662f\u5f88\u4e11\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>16<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4923498\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pabupa <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             302 \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923499\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u7528 Golang \u6700\u5feb                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923500\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Cuo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u80fd\u76f4\u63a5\u4ece\u524d\u6bb5\u8bf7\u6c42\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923501\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tcsky <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e11\u6ca1\u5173\u7cfb, \u597d\u7528\u554a.<br \/>\u6709\u4e2a sjson \u5e93\u53ef\u4ee5\u76f4\u63a5\u6539 json \u5b57\u7b26\u4e32.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923502\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dimlau <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Cuo <br \/>@fx <br \/>@pabupa <\/p>\n<p>json \u5730\u5740\u91cc\u6709 md5\uff0c\u800c\u4e14\u65b0\u52a0\u7684\u5185\u5bb9\u4e5f\u662f go \u4ece\u6570\u636e\u5e93\u91cc\u53d6\u51fa\u6765\u7684\u2026\u2026<br \/>\u6240\u4ee5\uff0c\u5982\u679c\u8981\u662f\u524d\u7aef\u505a\u7684\u8bdd\uff0c\u5f97\u4e24\u6b21 fetch \u3002<\/p>\n<p>\u8bf7\u95ee\uff0c\u5404\u4f4d\u610f\u601d\u662f\u8bf4\uff0c\u5373\u4fbf\u8fd9\u6837\u4e5f\u6bd4\u4e0a\u8fb9\u90a3\u6837\u5904\u7406\u5f97\u5feb\u5417\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923503\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dimlau <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @tcsky \u597d\u561e\uff0c\u6211\u4e5f\u53bb\u627e\u627e\u770b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923504\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : neoblackcap <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dimlau \u662f\u4e0d\u662f\u793a\u4f8b\u4ee3\u7801\u6f0f\u4e86\u4e00\u4e9b\uff1f\u6211\u597d\u50cf\u6ca1\u770b\u5230\u6709&#8221;}&#8221;\u63d2\u5165\u8fdb\u53bb<br \/>\u6309\u6211\u7684\u7406\u89e3\uff0c\u5982\u679c\u4ec5\u4ec5\u662f\u5b57\u7b26\u4e32\u62fc\u63a5\uff0c\u4e0d\u6d89\u53ca\u5230\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\uff0c\u5404\u79cd\u5e93\u5e95\u5c42\u4fee\u6539\u7684\u903b\u8f91\u5e94\u8be5\u5927\u540c\u5c0f\u5f02\u3002\u6700\u591a\u53ef\u80fd\u4f1a\u6bd4\u4f60\u8fd9\u4e2a\u9ad8\u6548\u90a3\u4e48\u4e00\u70b9\uff0c\u533a\u522b\u5e94\u8be5\u4e0d\u5927\u3002\u4ec5\u4ec5\u662f API \u5c01\u88c5\u4e86\uff0c\u53ef\u80fd\u597d\u770b\u4e00\u70b9\u7f62\u4e86\u3002<br \/>\u6709\u7684\u5c01\u88c5\u8fd8\u6709\u53ef\u80fd\u6709\u989d\u5916\u7684\u5f00\u9500\u3002\u770b\u4f60\u7684\u9009\u62e9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923505\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jay777 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             sjson gjson                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923506\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jinliming2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u8981 ioutil.ReadAll\uff0c\u4f60\u8fd9\u4e2a\u53ea\u662f\u628a resp.Body \u7b2c\u4e00\u4e2a\u5b57\u8282\u53bb\u6389\u7684\u8bdd\uff0c\u8fd9\u6837\u5199\uff1a<br \/>resp, err := http.Get(&#8220;\/\/\/xxxxx.json&#8221;)<br \/>if err != nil {<br \/> panic(err)<br \/>}<br \/>defer resp.Body.Close()<br \/>fmt.Fprintf(w, `{&#8220;id&#8221;:&#8221;%s&#8221;,`, TOTID) \/\/ \u683c\u5f0f\u5316\u76f4\u63a5\u5199\u51fa<br \/>io.CopyN(ioutil.Discard, resp.Body, 1) \/\/ \u4e22\u5f03\u7b2c\u4e00\u4e2a\u5b57\u8282<br \/>io.Copy(w, resp.Body) \/\/ \u5199\u51fa\u5269\u4f59\u6570\u636e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923507\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jinliming2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @neoblackcap \u4ed6 http response \u91cc\u5e94\u8be5\u662f\u4e00\u4e2a\u5b8c\u6574\u7684 JSON\uff0c{&#8230;..}\uff0c\u4e0b\u9762\u4ed6\u628a\u7b2c\u4e00\u4e2a { \u53bb\u6389\u62fc\u4e0a\u4e86\u524d\u9762\u7684\u90a3\u4e00\u6bb5\uff0c} \u662f\u539f\u6765\u7684 JSON \u91cc\u5c31\u6709\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923508\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : neoblackcap <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jinliming2 \u54e6\uff0c\u4f60\u4e0d\u8bf4\u6211\u90fd\u6ca1\u641e\u61c2\uff0c\u7684\u786e\u662f\u8fd9\u6837                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923509\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : treblex <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u662f json \u7684\u8bdd \u5199\u4e2a struct \u7ed1\u5b9a \u6216\u8005\u7ed1\u5b9a map[string]interface{},\u7136\u540e\u5728\u4fee\u6539\u4f1a\u65b9\u4fbf\u70b9\u5427\uff0c<br \/>\u76f4\u63a5\u62fc\u5b57\u7b26\u4e32\u662f\u56e0\u4e3a\u6709\u6027\u80fd\u8981\u6c42\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923510\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hongweiliuruige <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u786e\u5b9e\u4e11\u554a\uff0c\uff0c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923511\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qq1340691923 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u79cd\u64cd\u4f5c\u5c31\u4e0d\u8be5 go \u6765\u5904\u7406,node \u505a\u4e2d\u95f4\u5c42\u4e0d\u9999\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923512\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dimlau <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jinliming2 \u8bf7\u95ee\uff0c#9 \u8fd9\u6837\u4f9d\u7136\u8fd8\u662f\u91ce\u8def\u5b50\u5417\uff1f<br \/>\u662f\u4e0d\u662f\u4e00\u822c\u4e0d\u4f1a\u8fd9\u6837\u5904\u7406\uff1f<\/p>\n<p>\u56e0\u4e3a\u611f\u89c9\u5982 @suke971219 \u6240\u8bf4\u5199 struct \u6709\u70b9\u7e41\u7410\uff0c\u7528\u5230\u7684\u6570\u636e\u5728 json \u7684\u4e0d\u540c\u5c42\u7ea7\uff0cstruct \u8981\u5199\u597d\u51e0\u5c42\uff1f<br \/>\u4e0d\u5982\u5728\u524d\u7aef\u7528 js \u53d6\u60f3\u8981\u7684\u5c31\u5b8c\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923513\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jinliming2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dimlau \u5177\u4f53\u60c5\u51b5\u5177\u4f53\u5bf9\u5f85\u3002\u4f60\u8fd9\u4e2a\u9700\u6c42\u91cc\u9762\uff0cresp.Body \u5b8c\u5168\u6ca1\u7528\uff0c\u6240\u4ee5\u76f4\u63a5\u6d41\u8f6c\u53d1\u5c31\u884c\uff0c\u6548\u7387\u66f4\u9ad8\uff0c\u4e0d\u9700\u8981\u5168\u8bfb\u5230\u5185\u5b58\u91cc\u5904\u7406\u3002<br \/>\u800c\u5176\u4ed6\u7684 xxjson \u5566\uff0cstruct \u7ed1\u5b9a\u5566\u4e4b\u7c7b\u7684\uff0c\u90fd\u662f\u8981\u628a\u6574\u4e2a json \u8bfb\u5230\u5185\u5b58\u91cc\uff0c\u89e3\u6790\uff0c\u7136\u540e\u4fee\u6539\uff0c\u7136\u540e\u5e8f\u5217\u5316\uff0c\u518d\u5199\u51fa\uff0c\u8fd9\u4e2a\u6548\u7387\u5c31\u5f88\u4f4e\u4e86\uff0c\u5bf9\u4f60\u8fd9\u4e2a\u9700\u6c42\u6765\u8bf4\u5c31\u6ca1\u6709\u5fc5\u8981\u4e86\u3002\u9664\u975e\u4f60\u9700\u8981\u5bf9 resp.Body \u505a\u4e00\u4e9b\u989d\u5916\u7684\u5904\u7406\u3002<br \/>\u5f53\u7136\uff0c\u5982\u679c\u4f60\u7684 jdon \u5f88\u5c0f\u7684\u8bdd\uff0c\u4e0d\u5728\u4e4e\u8fd9\u70b9\u6027\u80fd\uff0c\u800c\u8fd9\u6837\u5199\u53c8\u4e0d\u591f\u7f8e\u89c2\u53ef\u8bfb\u7684\u8bdd\uff0c\u90a3\u4e0a\u7684\u90a3\u4e9b\u5176\u4ed6\u7684\u65b9\u6848\u4e5f\u5b8c\u5168\u53ef\u4ee5\u91c7\u7528\u3002<br \/>\u6211\u89c9\u5f97\u4f60\u8fd9\u79cd\u7b80\u5355\u7684\u51fd\u6570\uff0c\u53ea\u8981\u5199\u597d\u6ce8\u91ca\uff0c\u57fa\u672c\u4e0a\u6ca1\u5565\u95ee\u9898\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\uff1a\u8fdc\u7a0b Get \u5230\u590d\u6742 JSO&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/277704"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=277704"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/277704\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277704"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}