{"id":41513,"date":"2024-12-01T10:27:56","date_gmt":"2024-12-01T02:27:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/41513\/"},"modified":"2024-12-01T10:27:56","modified_gmt":"2024-12-01T02:27:56","slug":"%e5%a6%82%e4%bd%95%e8%ae%bf%e9%97%ae%e8%af%a5%e7%bb%93%e6%9e%84%e4%b8%ad%e7%9a%84%e6%9f%90%e4%ba%9b%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/41513\/","title":{"rendered":"\u5982\u4f55\u8bbf\u95ee\u8be5\u7ed3\u6784\u4e2d\u7684\u67d0\u4e9b\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>\u5982\u4f55\u8bbf\u95ee\u8be5\u7ed3\u6784\u4e2d\u7684\u67d0\u4e9b\u503c<\/span><\/p>\n<h1>\u5982\u4f55\u8bbf\u95ee\u8be5\u7ed3\u6784\u4e2d\u7684\u67d0\u4e9b\u503c<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-20 14:39: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>\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u7ed3\u5408\u6211\u4e4b\u524d\u9762\u8bd5\u7684\u5404\u79cd\u7ecf\u5386\u548c\u5b9e\u6218\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u95ee\u9898\u89e3\u51b3\u7ecf\u9a8c\u6574\u7406\u7684\uff0c\u5e0c\u671b\u8fd9\u7bc7\u300a\u5982\u4f55\u8bbf\u95ee\u8be5\u7ed3\u6784\u4e2d\u7684\u67d0\u4e9b\u503c\u300b\u5bf9\u4f60\u6709\u5f88\u5927\u5e2e\u52a9\uff01\u6b22\u8fce\u6536\u85cf\uff0c\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u9700\u8981\u7684\u670b\u53cb\u5b66\u4e60~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728 go \u4e2d\u8bb0\u5f55\u4e00\u4e9b\u5185\u5bb9\u3002\u8fd9\u662f\u503c\uff0c\u4e0b\u9762\u662f\u6211\u8bb0\u5f55 reflect.typeof(attributes.pdp.sellableunits[i].attributes) \u65f6\u7684\u7ed3\u679c\uff1a<\/p>\n<pre>[{22555278 val 03.5}]\n[{22554867 val 04.0}]\n[{22555002 val 04.5}]\n[{22555279 val 05.0}]\n[{22555280 val 05.5}]\n[{22555144 val 06.0}]\n[{22555145 val 06.5}]\n[{22555146 val 07.0}]\n\n\/\/ typeof\n[1]struct { id string \"json:\\\"id\\\"\"; type string \"json:\\\"type\\\"\"; value string \"json:\\\"value\\\"\" }\n[1]struct { id string \"json:\\\"id\\\"\"; type string \"json:\\\"type\\\"\"; value string \"json:\\\"value\\\"\" }\n[1]struct { id string \"json:\\\"id\\\"\"; type string \"json:\\\"type\\\"\"; value string \"json:\\\"value\\\"\" }\n[1]struct { id string \"json:\\\"id\\\"\"; type string \"json:\\\"type\\\"\"; value string \"json:\\\"value\\\"\" }\n[1]struct { id string \"json:\\\"id\\\"\"; type string \"json:\\\"type\\\"\"; value string \"json:\\\"value\\\"\" }\n[1]struct { id string \"json:\\\"id\\\"\"; type string \"json:\\\"type\\\"\"; value string \"json:\\\"value\\\"\" }\n[1]struct { id string \"json:\\\"id\\\"\"; type string \"json:\\\"type\\\"\"; value string \"json:\\\"value\\\"\" }\n[1]struct { id string \"json:\\\"id\\\"\"; type string \"json:\\\"type\\\"\"; value string \"json:\\\"value\\\"\" }<\/pre>\n<p>\u6211\u5e0c\u671b\u80fd\u591f\u4ec5\u8bb0\u5f55 id \u5b57\u7b26\u4e32\uff0c\u5728\u672c\u4f8b\u4e2d\u662f\u4ee3\u7801\u5757\u9876\u90e8\u7684\u8bb8\u591a\u6570\u5b57\u5b57\u7b26\u4e32\uff0822555278\u300122554867\u300122555002 \u7b49&#8230;\uff09<\/p>\n<p>\u8fd9\u662f\u6211\u7684\u4ee3\u7801\u6765\u8bb0\u5f55\u6240\u6709\u8fd9\u4e9b<\/p>\n<pre>\/\/ Struct\ntype sizeJ struct {\n    Pdp struct {\n        Units []struct {\n            Attributes [1]struct {\n                ID    string `json:\"id\"`\n                Type  string `json:\"type\"`\n                Value string `json:\"value\"`\n            } `json:\"attributes\"`\n        } `json:\"Units\"`\n    } `json:\"pdp\"`\n}\n\n\/\/ ...\n        body, _ := ioutil.ReadAll(resp.Body)\n\n        xml := strings.NewReader(string(body))\n\n        j, _ := xj.Convert(xml)\n        if err != nil {\n            log.Fatal(err)\n        }\n\n        var attributes sizeJ\n        json.Unmarshal([]byte(j.String()), &amp;attributes)\n\n        for i := 0; i &lt; len(attributes.Pdp.Units); i++ {\n            fmt.Println(reflect.TypeOf(attributes.Pdp.Units[i].Attributes))\n\n        }<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u7684\u7c7b\u578b\u58f0\u660e\u4e3a\uff1a<\/p>\n<pre>type sizej struct {\n    pdp struct {\n        units []struct {\n            attributes [1]struct {\n                id    string `json:\"id\"`\n                type  string `json:\"type\"`\n                value string `json:\"value\"`\n            } `json:\"attributes\"`\n        } `json:\"units\"`\n    } `json:\"pdp\"`\n}<\/pre>\n<p>\u60a8\u53ef\u4ee5\u53ea\u6253\u5370 id\uff1a<\/p>\n<pre>for i := 0; i &lt; len(attributes.Pdp.Units); i++ {\n    \/\/ fmt.Println(reflect.TypeOf(attributes.Pdp.Units[i].Attributes))\n    fmt.Printf(\"ID: %s\\n\", attributes.Pdp.Units[i].Attributes[0].ID)\n\n}<\/pre>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u8bbf\u95ee\u8be5\u7ed3\u6784\u4e2d\u7684\u67d0\u4e9b\u503c\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5982\u4f55\u8bbf\u95ee\u8be5\u7ed3\u6784\u4e2d\u7684\u67d0\u4e9b\u503c \u5982\u4f55\u8bbf\u95ee\u8be5\u7ed3\u6784\u4e2d\u7684\u67d0\u4e9b\u503c \u6765\u6e90\uff1astackoverflow 2024-04-20 14:39:35 0\u6d4f\u89c8 \u6536\u85cf \u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u7ed3\u5408\u6211\u4e4b\u524d\u9762\u8bd5\u7684\u5404\u79cd\u7ecf\u5386\u548c\u5b9e\u6218\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u95ee\u9898\u89e3\u51b3\u7ecf\u9a8c\u6574\u7406\u7684\uff0c\u5e0c\u671b\u8fd9\u7bc7\u300a\u5982\u4f55\u8bbf\u95ee\u8be5\u7ed3\u6784\u4e2d\u7684\u67d0\u4e9b\u503c\u300b\u5bf9\u4f60\u6709\u5f88\u5927\u5e2e\u52a9\uff01\u6b22\u8fce\u6536\u85cf\uff0c\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u9700\u8981\u7684\u670b\u53cb\u5b66\u4e60~ \u95ee\u9898\u5185\u5bb9 \u6211\u6b63\u5728 go \u4e2d\u8bb0\u5f55\u4e00\u4e9b\u5185\u5bb9\u3002\u8fd9\u662f\u503c\uff0c\u4e0b\u9762\u662f\u6211\u8bb0\u5f55 reflect.typeof(attributes.pdp.sellableunits[i].attributes) \u65f6\u7684\u7ed3\u679c\uff1a [{22555278 val 03.5}] [{22554867 val 04.0}] [{22555002 val 04.5}] [{22555279 val 05.0}] [{22555280 val 05.5}] [{22555144 val 06.0}] [{22555145 val 06.5}] [{22555146 val 07.0}] \/\/ typeof [1]struct { id string &#8220;json:\\&#8221;id\\&#8221;&#8221;; type string &#8220;json:\\&#8221;type\\&#8221;&#8221;; value string [&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-41513","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41513","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=41513"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/41513\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=41513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=41513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=41513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}