{"id":37060,"date":"2024-11-26T17:53:33","date_gmt":"2024-11-26T09:53:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37060\/"},"modified":"2024-11-26T17:53:33","modified_gmt":"2024-11-26T09:53:33","slug":"json%e6%80%8e%e4%b9%88%e8%bd%ac%e6%95%b0%e7%bb%84-java%e5%af%b9%e8%b1%a1%e6%95%b0%e7%bb%84%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37060\/","title":{"rendered":"json\u600e\u4e48\u8f6c\u6570\u7ec4 java\u5bf9\u8c61\u6570\u7ec4\u5bf9\u8c61"},"content":{"rendered":"<blockquote><p>\n  \u53ef\u4ee5\u4f7f\u7528 gson \u5e93\u8f6c\u6362 json \u8f6c\u6362\u4e3a java \u5bf9\u8c61\u6570\u7ec4\uff1a\u6dfb\u52a0 gson \u4f9d\u8d56\u9879\u3002\u521b\u5efa gson \u5bf9\u8c61\u3002\u5c06 json \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a java \u5bf9\u8c61\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111300334857897.jpg\" class=\"aligncenter\" title=\"json\u600e\u4e48\u8f6c\u6570\u7ec4 java\u5bf9\u8c61\u6570\u7ec4\u5bf9\u8c61\u63d2\u56fe\" alt=\"json\u600e\u4e48\u8f6c\u6570\u7ec4 java\u5bf9\u8c61\u6570\u7ec4\u5bf9\u8c61\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 JSON \u8f6c\u6362\u4e3a Java \u5bf9\u8c61\u6570\u7ec4\uff1f<\/strong><\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 Gson \u5e93\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06 JSON \u8f6c\u6362\u4e3a Java \u5bf9\u8c61\u6570\u7ec4\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li><strong>\u6dfb\u52a0 Gson \u4f9d\u8d56\u9879\uff1a<\/strong><\/li>\n<\/ol>\n<pre>&lt;dependency&gt;\n  &lt;groupId&gt;com.google.code.gson&lt;\/groupId&gt;\n  &lt;artifactId&gt;gson&lt;\/artifactId&gt;\n  &lt;version&gt;2.9.0&lt;\/version&gt;\n&lt;\/dependency&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u521b\u5efa Gson \u5bf9\u8c61\uff1a<\/strong><\/li>\n<\/ol>\n<pre>Gson gson = new Gson();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u5c06 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a Java \u5bf9\u8c61\u6570\u7ec4\uff1a<\/strong><\/li>\n<\/ol>\n<pre>String json = \"[{\"name\": \"John\", \"age\": 25},{\"name\": \"Mary\", \"age\": 30}]\";\n\nPerson[] people = gson.fromJson(json, Person[].class);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0cPerson \u662f\u4e00\u4e2a\u5177\u6709 name \u548c age \u5b57\u6bb5\u7684\u7b80\u5355 POJO \u7c7b\u3002people \u6570\u7ec4\u73b0\u5728\u5305\u542b\u4e86 JSON \u4e2d\u7684\u4e24\u4e2a\u5bf9\u8c61\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u60a8\u7684 JSON \u5b57\u7b26\u4e32\u683c\u5f0f\u6b63\u786e\uff0c\u4e14\u4e0e\u8981\u8f6c\u6362\u7684\u5bf9\u8c61\u6570\u7ec4\u7684\u7ed3\u6784\u76f8\u5339\u914d\u3002<\/li>\n<li>Gson \u5e93\u8fd8\u53ef\u4ee5\u5c06 Java \u5bf9\u8c61\u8f6c\u6362\u4e3a JSON\uff0c\u5e76\u63d0\u4f9b\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\uff0c\u4f8b\u5982\u81ea\u5b9a\u4e49\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjson\u600e\u4e48\u8f6c\u6570\u7ec4 java\u5bf9\u8c61\u6570\u7ec4\u5bf9\u8c61\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>\u53ef\u4ee5\u4f7f\u7528 gson \u5e93\u8f6c\u6362 json \u8f6c\u6362\u4e3a java \u5bf9\u8c61\u6570\u7ec4\uff1a\u6dfb\u52a0 gson \u4f9d\u8d56\u9879\u3002\u521b\u5efa gson \u5bf9\u8c61\u3002\u5c06 json \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a java \u5bf9\u8c61\u6570\u7ec4\u3002 \u5982\u4f55\u5c06 JSON \u8f6c\u6362\u4e3a Java \u5bf9\u8c61\u6570\u7ec4\uff1f \u7b54\u6848\uff1a \u4f7f\u7528 Gson \u5e93\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06 JSON \u8f6c\u6362\u4e3a Java \u5bf9\u8c61\u6570\u7ec4\u3002 \u8be6\u7ec6\u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u6dfb\u52a0 Gson \u4f9d\u8d56\u9879\uff1a &lt;dependency&gt; &lt;groupId&gt;com.google.code.gson&lt;\/groupId&gt; &lt;artifactId&gt;gson&lt;\/artifactId&gt; &lt;version&gt;2.9.0&lt;\/version&gt; &lt;\/dependency&gt; \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa Gson \u5bf9\u8c61\uff1a Gson gson = new Gson(); \u767b\u5f55\u540e\u590d\u5236 \u5c06 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a Java \u5bf9\u8c61\u6570\u7ec4\uff1a String json [&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-37060","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37060","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=37060"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37060\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}