{"id":40178,"date":"2024-11-26T14:16:04","date_gmt":"2024-11-26T06:16:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/40178\/"},"modified":"2024-11-26T14:16:04","modified_gmt":"2024-11-26T06:16:04","slug":"%e5%af%b9%e8%b1%a1%e6%80%8e%e4%b9%88%e8%bd%ac%e6%8d%a2%e6%88%90%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84-java","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/40178\/","title":{"rendered":"\u5bf9\u8c61\u600e\u4e48\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u6570\u7ec4 java"},"content":{"rendered":"<blockquote><p>\n  \u6709\u56db\u79cd\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u65b9\u6cd5\uff1a\u76f4\u63a5\u901a\u8fc7 tostring() \u548c split() \u65b9\u6cd5\uff1b\u4f7f\u7528\u53cd\u5c04\u83b7\u53d6\u5b57\u6bb5\u6216\u65b9\u6cd5\u7684\u503c\u5e76\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff1b\u501f\u52a9 gson \u5e93\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a json \u518d\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\uff1b\u4f7f\u7528 apache commons lang \u5e93\u7684 stringutils.split() \u65b9\u6cd5\u6309\u5206\u9694\u7b26\u62c6\u5206\u5b57\u7b26\u4e32\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111722095980857.jpg\" class=\"aligncenter\" title=\"\u5bf9\u8c61\u600e\u4e48\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u6570\u7ec4 java\u63d2\u56fe\" alt=\"\u5bf9\u8c61\u600e\u4e48\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u6570\u7ec4 java\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 toString() \u65b9\u6cd5\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u4f7f\u7528 split() \u65b9\u6cd5\u5c06\u5176\u6309\u7279\u5b9a\u5206\u9694\u7b26\u62c6\u5206\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002<\/p>\n<pre>String[] stringArray = object.toString().split(\",\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5229\u7528\u53cd\u5c04\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5982\u679c\u4f60\u77e5\u9053\u5bf9\u8c61\u7684\u7c7b\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cd\u5c04\u6765\u83b7\u53d6\u5176\u5b57\u6bb5\u6216\u65b9\u6cd5\u7684\u503c\uff0c\u5e76\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<pre>Class&lt;?&gt; clazz = object.getClass();\nField[] fields = clazz.getDeclaredFields();\nString[] stringArray = new String[fields.length];\nfor (int i = 0; i &lt; fields.length; i++) {\n    Field field = fields[i];\n    field.setAccessible(true);\n    stringArray[i] = field.get(object).toString();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Gson \u5e93\uff1a<\/strong><\/p>\n<p>Gson \u5e93\u63d0\u4f9b\u4e86\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a JSON \u7684\u65b9\u6cd5\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5c06 JSON \u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002<\/p>\n<pre>Gson gson = new Gson();\nJsonObject jsonObject = gson.toJsonTree(object).getAsJsonObject();\nString[] stringArray = gson.fromJson(jsonObject.toString(), String[].class);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Apache Commons Lang \u5e93\uff1a<\/strong><\/p>\n<p>Apache Commons Lang \u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a StringUtils.split() \u65b9\u6cd5\uff0c\u53ef\u4ee5\u6309\u5206\u9694\u7b26\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002<\/p>\n<pre>String[] stringArray = StringUtils.split(object.toString(), \",\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5bf9\u8c61\u600e\u4e48\u8f6c\u6362\u6210 java\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u56db\u79cd\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u7684\u65b9\u6cd5\uff1a\u76f4\u63a5\u901a\u8fc7 tostring() \u548c split() \u65b9\u6cd5\uff1b\u4f7f\u7528\u53cd\u5c04\u83b7\u53d6\u5b57\u6bb5\u6216\u65b9\u6cd5\u7684\u503c\u5e76\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff1b\u501f\u52a9 gson \u5e93\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a json \u518d\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\uff1b\u4f7f\u7528 apache commons lang \u5e93\u7684 stringutils.split() \u65b9\u6cd5\u6309\u5206\u9694\u7b26\u62c6\u5206\u5b57\u7b26\u4e32\u3002 \u5982\u4f55\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a \u76f4\u63a5\u65b9\u6cd5\uff1a \u4f7f\u7528 toString() \u65b9\u6cd5\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u4f7f\u7528 split() \u65b9\u6cd5\u5c06\u5176\u6309\u7279\u5b9a\u5206\u9694\u7b26\u62c6\u5206\u4e3a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002 String[] stringArray = object.toString().split(&#8220;,&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u5229\u7528\u53cd\u5c04\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5982\u679c\u4f60\u77e5\u9053\u5bf9\u8c61\u7684\u7c7b\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cd\u5c04\u6765\u83b7\u53d6\u5176\u5b57\u6bb5\u6216\u65b9\u6cd5\u7684\u503c\uff0c\u5e76\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002 Class&lt;?&gt; clazz = object.getClass(); Field[] fields = clazz.getDeclaredFields(); String[] stringArray = new String[fields.length]; for (int i = 0; i &lt; fields.length; i++) { Field field [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-40178","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40178","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=40178"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/40178\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=40178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=40178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=40178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}