{"id":207033,"date":"2025-07-08T08:12:09","date_gmt":"2025-07-08T00:12:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207033\/"},"modified":"2025-07-08T08:12:09","modified_gmt":"2025-07-08T00:12:09","slug":"%e8%bd%ac%e6%8d%a2%e5%85%b7%e6%9c%89%e5%8d%95%e4%b8%aa%e6%b7%b7%e5%90%88%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e6%95%b0%e7%bb%84%e7%9a%84%e5%8d%95%e4%b8%aa%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207033\/","title":{"rendered":"\u8f6c\u6362\u5177\u6709\u5355\u4e2a\u6df7\u5408\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u7684\u5355\u4e2a\u5b57\u7b26\u4e32"},"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>\u8f6c\u6362\u5177\u6709\u5355\u4e2a\u6df7\u5408\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u7684\u5355\u4e2a\u5b57\u7b26\u4e32<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 16:27:36<\/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\u7ed9\u5927\u5bb6\u5206\u4eab\u300a\u8f6c\u6362\u5177\u6709\u5355\u4e2a\u6df7\u5408\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u7684\u5355\u4e2a\u5b57\u7b26\u4e32\u300b\uff0c\u8986\u76d6\u4e86Golang\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u5982\u4f55\u8f6c\u6362\u5176\u4e2d\u5305\u542b\u5355\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u5355\u4e2a\u5b57\u7b26\u4e32\u3002<\/p>\n<pre>func main() {\n  stringarrayinstring := \"[\\\"hello\\\",\\\"hai\\\",\\\"how are you!\\\"]\" \/\/single string which has string array in it\n    fmt.println(stringarrayinstring)\n\n \/\/ code to convert to the string array\n \/\/ convertedstring\n}<\/pre>\n<p>\u8f93\u51fa\u5fc5\u987b\u662f\u8fd9\u6837\u7684<\/p>\n<pre>convertedstring[0] = \"hello\"\nconvertedstring[1] = \"hai\"\nconvertedstring[2] = \"how are you!\"<\/pre>\n<p>\u5982\u679c\u4e0a\u9762\u7684\u8f93\u5165\u5b57\u7b26\u4e32\u6709int\u3001string\u3001json\u7c7b\u578b\u7b49\u6df7\u5408\u6570\u636e\u7c7b\u578b\u662f\u5426\u53ef\u4ee5 \u4f8b\u5982<\/p>\n<pre>stringArrayInString := \"[\\\"Hello\\\",\\\"{\\\"msg\\\":\\\"Hai\\\"}\\\",123]\"\n\n\/\/after converting\n\nconvertedString[0] = \"Hello\"\nconvertedString[1] = \"{\\\"msg\\\":\\\"Hai\\\"}\"\nconvertedString[2] = 123<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u62e5\u6709\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\u662f\u4e00\u4e2a\u6709\u6548\u7684 json \u6570\u7ec4\uff0c\u56e0\u6b64\u60a8\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<pre>var convertedstring []string\njson.unmarshal([]byte(str),&amp;convertedstring)<\/pre>\n<p>\u5982\u679c\u8be5\u6570\u7ec4\u4e2d\u6709\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u6765\u5b9e\u73b0\uff0c\u60a8\u9700\u8981\u4e00\u4e2a interface{} \u6570\u7ec4\uff1a<\/p>\n<pre>var convertedData []interface{}\njson.Unmarshal([]byte(str),&amp;convertedData)<\/pre>\n<p>\u7136\u540e\u60a8\u9700\u8981\u68c0\u67e5\u8be5\u6570\u7ec4\u4e2d\u5404\u4e2a\u5143\u7d20\u7684\u7c7b\u578b\u4ee5\u627e\u51fa\u5b83\u4eec\u662f\u4ec0\u4e48\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u8f6c\u6362\u5177\u6709\u5355\u4e2a\u6df7\u5408\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u7684\u5355\u4e2a\u5b57\u7b26\u4e32\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\u516c\u4f17\u53f7\uff01<\/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-207033","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207033","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=207033"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207033\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}