{"id":207810,"date":"2025-07-08T10:59:40","date_gmt":"2025-07-08T02:59:40","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207810\/"},"modified":"2025-07-08T10:59:40","modified_gmt":"2025-07-08T02:59:40","slug":"%e5%b0%9d%e8%af%95%e8%a7%a3%e7%a0%81-json-%e7%9a%84%e4%b8%bb%e4%bd%93%e6%97%b6%e5%87%ba%e7%8e%b0%e9%94%99%e8%af%afdata1-body-%e6%9c%aa%e5%ae%9a%e4%b9%89%ef%bc%88%e5%ad%97%e8%8a%82%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207810\/","title":{"rendered":"\u5c1d\u8bd5\u89e3\u7801 json \u7684\u4e3b\u4f53\u65f6\u51fa\u73b0\u9519\u8bef\u201cdata1.Body \u672a\u5b9a\u4e49\uff08\u5b57\u8282\u7c7b\u578b\u6ca1\u6709\u5b57\u6bb5\u6216\u65b9\u6cd5\u4e3b\u4f53\uff09\u201d"},"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>\u5c1d\u8bd5\u89e3\u7801 json \u7684\u4e3b\u4f53\u65f6\u51fa\u73b0\u9519\u8bef\u201cdata1.Body \u672a\u5b9a\u4e49\uff08\u5b57\u8282\u7c7b\u578b\u6ca1\u6709\u5b57\u6bb5\u6216\u65b9\u6cd5\u4e3b\u4f53\uff09\u201d<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-25 19:30:39<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5c1d\u8bd5\u89e3\u7801 json \u7684\u4e3b\u4f53\u65f6\u51fa\u73b0\u9519\u8bef\u201cdata1.Body \u672a\u5b9a\u4e49\uff08\u5b57\u8282\u7c7b\u578b\u6ca1\u6709\u5b57\u6bb5\u6216\u65b9\u6cd5\u4e3b\u4f53\uff09\u201d\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\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u518d\u6b21\u5c1d\u8bd5\u83b7\u53d6\u6b64\u6570\u636e\uff0c\u4f46\u5b83\u8fd4\u56de\u9519\u8bef<\/p>\n<pre>data.body undefined (type []byte has no field or method body)<\/pre>\n<p>\u5728\u6b64\u4ee3\u7801\u7684\u7b2c 16 \u884c\u548c\u7b2c 23 \u884c\u3002\u6240\u4ee5\u5f53\u5b83\u89e3\u7801 json \u65f6 \u5982\u679c\u6709\u4eba\u80fd\u5e2e\u52a9\u6211\uff0c \u8fd9\u662f\u6211\u7684\u4ee3\u7801<\/p>\n<pre>func SkyblockActiveAuctions() (structs.SkyblockActiveAuctions, error) {\n    var auctions structs.SkyblockActiveAuctions\n    startTime := time.Now()\n    statusCode, data, err := fasthttp.Get(nil, \"https:\/\/api.hypixel.net\/skyblock\/auctions\")\n    if err != nil {\n        return auctions, err\n    }\n    fmt.Println(statusCode)\n    var totalPages = auctions.TotalAuctions\n    for i := 0; i &lt; totalPages; i++ {\n        statusCode, data1, err := fasthttp.Get(nil, \"https:\/\/api.hypixel.net\/skyblock\/auctions\")\n        if err != nil {\n            return auctions, err\n        }\n        fmt.Println(statusCode)\n        json.NewDecoder(data1.Body).Decode(&amp;auctions)\n        fmt.Println(auctions.LastUpdated)\n    }\n    endTime := time.Now()\n    var timeTook = endTime.Sub(startTime).Milliseconds()\n    fmt.Println(data)\n\n    json.NewDecoder(data.Body).Decode(&amp;auctions)\n\n    fmt.Println(auctions.LastUpdated)\n    fmt.Println(timeTook)\n\n    return auctions, err\n}<\/pre>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<pre>json.newdecoder(data.body).decode(&amp;auctions)<\/pre>\n<pre>data.body undefined (type []byte has no field or method body)<\/pre>\n<p>\u3002<\/p>\n<p>\uff0c\u4f46\u7531\u4e8e<code>fasthttp<\/code>\u5df2\u7ecf\u5c06\u6570\u636e\u8bfb\u5165<code>[]byte<\/code>\uff0c\u6240\u4ee5\u4f7f\u7528\u4f1a\u66f4\u5408\u9002\uff1a<\/p>\n<pre>err := json.Unmarshal(data, &amp;auctions)\n    if err != nil {\n         return nil, err\n    }<\/pre>\n<p>\u4e0d\u8981\u5fd8\u8bb0\u5904\u7406\u6765\u81ea <code>json.unmarshal<\/code> \u7684\u9519\u8bef\uff08\u6216\u8005\u6765\u81ea <code>json.decoder.decode<\/code> \u7684\u9519\u8bef\uff09\u3002\u5982\u679c json \u89e3\u6790\u5931\u8d25\uff0c<code>acutions<\/code> \u5c06\u4e0d\u4f1a\u4fdd\u5b58\u9884\u671f\u7684\u6570\u636e\uff0c\u56e0\u6b64\u60a8\u5e94\u8be5\u5904\u7406\u8fd9\u79cd\u53ef\u80fd\u6027\u3002<\/p>\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\u5c1d\u8bd5\u89e3\u7801 json \u7684\u4e3b\u4f53\u65f6\u51fa\u73b0\u9519\u8bef\u201cdata1.Body \u672a\u5b9a\u4e49\uff08\u5b57\u8282\u7c7b\u578b\u6ca1\u6709\u5b57\u6bb5\u6216\u65b9\u6cd5\u4e3b\u4f53\uff09\u201d\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\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; &#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-207810","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207810","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=207810"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207810\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}