{"id":155,"date":"2020-04-19T05:40:41","date_gmt":"2020-04-19T05:40:41","guid":{"rendered":"http:\/\/feellikelearning.com\/?p=155"},"modified":"2020-04-19T05:52:24","modified_gmt":"2020-04-19T05:52:24","slug":"cn-quick-tutorial-to-gson","status":"publish","type":"post","link":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/","title":{"rendered":"Gson\u5165\u95e8 | Quick tutorial to Gson"},"content":{"rendered":"\n<p>Gson\u662fGoogle\u7684\u5f00\u6e90\u7684\u5904\u7406Json\u7684library\u3002\u4e2a\u4eba\u89c9\u5f97\u6bd4<a href=\"https:\/\/github.com\/FasterXML\/jackson\">Jackson<\/a>\u597d\u7528\u3002<\/p>\n\n\n\n<p>\u628a<a href=\"https:\/\/github.com\/google\/gson\">gson<\/a>\u6dfb\u52a0\u5230build.gradle\u7684dependency\u91cc\uff0cgradle\u5165\u95e8\u8bf7\u53c2\u8003\u4e4b\u524d\u535a\u6587\u201d<a href=\"http:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-how-to-create-a-new-java-project-using-gradle\/\">\u600e\u6837\u7528gradle\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684Java\u9879\u76ee | how to create a new Java project using gradle<\/a>\u201c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dependencies {\n    implementation 'com.google.code.gson:gson:2.8.6'\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"646\" height=\"250\" src=\"http:\/\/feellikelearning.com\/wp-content\/uploads\/2020\/04\/image-5.png\" alt=\"\" class=\"wp-image-156\"\/><figcaption>\u70b9\u51fbIntelij Idea Gradle Plugin\u5de6\u4e0a\u89d2\u7684\u201c\u5237\u65b0\u201d<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"818\" height=\"192\" src=\"http:\/\/feellikelearning.com\/wp-content\/uploads\/2020\/04\/image-6.png\" alt=\"\" class=\"wp-image-157\"\/><figcaption>\u5237\u65b0\u540e\uff0c\u5728\u5de6\u8fb9\u9879\u76ee\u7ed3\u6784\u7684External Libraries\u91cc\u770b\u5230gson\uff0c\u5c31\u662f\u6dfb\u52a0\u6210\u529f\u4e86<\/figcaption><\/figure>\n\n\n\n<p>\u4f7f\u7528Gson\u4f8b\u5b50<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Gson gson = new Gson();\nString json = gson.toJson(someObject)<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91ccjson\u662f\u7d27\u51d1\u578b\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Gson gson = new GsonBuilder().setPrettyPrinting().create();\nString json = gson.toJson(someObject);<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u7684json\u662fpretty print\u7684<\/p>\n\n\n\n<p>\u4f8b\u5b50<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nimport com.google.gson.Gson;\nimport com.google.gson.GsonBuilder;\n\npublic class GsonDemo {\n    public String name;\n    public String url;\n    public String description;\n\n    @Override\n    public String toString() {\n        Gson gson = new GsonBuilder()\n                .setPrettyPrinting()\n                .create();\n        return gson.toJson(this);\n    }\n\n    public static void main(String&#91;] args) {\n        GsonDemo gsonDemo = new GsonDemo();\n        gsonDemo.name = \"Feellikelearning\";\n        gsonDemo.url = \"feellikelearning.com\";\n        gsonDemo.description = \"feellikelearning.com - The blog about learning technology\";\n\n        System.out.println(gsonDemo);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u8fd0\u884c\u7ed3\u679c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"Feellikelearning\",\n  \"url\": \"feellikelearning.com\",\n  \"description\": \"feellikelearning.com - The blog about learning technology\"\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Gson\u662fGoogle\u7684\u5f00\u6e90\u7684\u5904\u7406Json\u7684library\u3002\u4e2a\u4eba\u89c9\u5f97\u6bd4Jackson\u597d\u7528\u3002 \u628agson\u6dfb\u52a0\u5230build.gradle\u7684dependency\u91cc\uff0cgradle\u5165\u95e8\u8bf7\u53c2\u8003\u4e4b\u524d\u535a\u6587\u201d\u600e\u6837\u7528gradle\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684Java\u9879\u76ee | how to create a new Java project using gradle\u201c\u3002 \u4f7f\u7528Gson\u4f8b\u5b50 \u8fd9\u91ccjson\u662f\u7d27\u51d1\u578b\u7684 \u8fd9\u91cc\u7684json\u662fpretty print\u7684 \u4f8b\u5b50 \u8fd0\u884c\u7ed3\u679c<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Gson\u5165\u95e8 | Quick tutorial to Gson | Feel Like Learning<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Gson\u5165\u95e8 | Quick tutorial to Gson | Feel Like Learning\" \/>\n<meta property=\"og:description\" content=\"Gson\u662fGoogle\u7684\u5f00\u6e90\u7684\u5904\u7406Json\u7684library\u3002\u4e2a\u4eba\u89c9\u5f97\u6bd4Jackson\u597d\u7528\u3002 \u628agson\u6dfb\u52a0\u5230build.gradle\u7684dependency\u91cc\uff0cgradle\u5165\u95e8\u8bf7\u53c2\u8003\u4e4b\u524d\u535a\u6587\u201d\u600e\u6837\u7528gradle\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684Java\u9879\u76ee | how to create a new Java project using gradle\u201c\u3002 \u4f7f\u7528Gson\u4f8b\u5b50 \u8fd9\u91ccjson\u662f\u7d27\u51d1\u578b\u7684 \u8fd9\u91cc\u7684json\u662fpretty print\u7684 \u4f8b\u5b50 \u8fd0\u884c\u7ed3\u679c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/\" \/>\n<meta property=\"og:site_name\" content=\"Feel Like Learning\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-19T05:40:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-19T05:52:24+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/feellikelearning.com\/wp-content\/uploads\/2020\/04\/image-5.png\" \/>\n<meta name=\"author\" content=\"feellikelearning\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"feellikelearning\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/\"},\"author\":{\"name\":\"feellikelearning\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"headline\":\"Gson\u5165\u95e8 | Quick tutorial to Gson\",\"datePublished\":\"2020-04-19T05:40:41+00:00\",\"dateModified\":\"2020-04-19T05:52:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/\"},\"wordCount\":38,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/\",\"url\":\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/\",\"name\":\"Gson\u5165\u95e8 | Quick tutorial to Gson | Feel Like Learning\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/#website\"},\"datePublished\":\"2020-04-19T05:40:41+00:00\",\"dateModified\":\"2020-04-19T05:52:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/feellikelearning.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Gson\u5165\u95e8 | Quick tutorial to Gson\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/feellikelearning.com\/#website\",\"url\":\"https:\/\/feellikelearning.com\/\",\"name\":\"Feel Like Learning\",\"description\":\"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230\",\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/feellikelearning.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\",\"name\":\"feellikelearning\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"caption\":\"feellikelearning\"},\"logo\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Gson\u5165\u95e8 | Quick tutorial to Gson | Feel Like Learning","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/","og_locale":"en_US","og_type":"article","og_title":"Gson\u5165\u95e8 | Quick tutorial to Gson | Feel Like Learning","og_description":"Gson\u662fGoogle\u7684\u5f00\u6e90\u7684\u5904\u7406Json\u7684library\u3002\u4e2a\u4eba\u89c9\u5f97\u6bd4Jackson\u597d\u7528\u3002 \u628agson\u6dfb\u52a0\u5230build.gradle\u7684dependency\u91cc\uff0cgradle\u5165\u95e8\u8bf7\u53c2\u8003\u4e4b\u524d\u535a\u6587\u201d\u600e\u6837\u7528gradle\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684Java\u9879\u76ee | how to create a new Java project using gradle\u201c\u3002 \u4f7f\u7528Gson\u4f8b\u5b50 \u8fd9\u91ccjson\u662f\u7d27\u51d1\u578b\u7684 \u8fd9\u91cc\u7684json\u662fpretty print\u7684 \u4f8b\u5b50 \u8fd0\u884c\u7ed3\u679c","og_url":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/","og_site_name":"Feel Like Learning","article_published_time":"2020-04-19T05:40:41+00:00","article_modified_time":"2020-04-19T05:52:24+00:00","og_image":[{"url":"http:\/\/feellikelearning.com\/wp-content\/uploads\/2020\/04\/image-5.png"}],"author":"feellikelearning","twitter_card":"summary_large_image","twitter_misc":{"Written by":"feellikelearning","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/#article","isPartOf":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/"},"author":{"name":"feellikelearning","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"headline":"Gson\u5165\u95e8 | Quick tutorial to Gson","datePublished":"2020-04-19T05:40:41+00:00","dateModified":"2020-04-19T05:52:24+00:00","mainEntityOfPage":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/"},"wordCount":38,"commentCount":0,"publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/","url":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/","name":"Gson\u5165\u95e8 | Quick tutorial to Gson | Feel Like Learning","isPartOf":{"@id":"https:\/\/feellikelearning.com\/#website"},"datePublished":"2020-04-19T05:40:41+00:00","dateModified":"2020-04-19T05:52:24+00:00","breadcrumb":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/04\/19\/cn-quick-tutorial-to-gson\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/feellikelearning.com\/"},{"@type":"ListItem","position":2,"name":"Gson\u5165\u95e8 | Quick tutorial to Gson"}]},{"@type":"WebSite","@id":"https:\/\/feellikelearning.com\/#website","url":"https:\/\/feellikelearning.com\/","name":"Feel Like Learning","description":"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230","publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/feellikelearning.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a","name":"feellikelearning","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","caption":"feellikelearning"},"logo":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/"},"url":"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/"}]}},"_links":{"self":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/155"}],"collection":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/comments?post=155"}],"version-history":[{"count":7,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/155\/revisions"}],"predecessor-version":[{"id":165,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/155\/revisions\/165"}],"wp:attachment":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/media?parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/categories?post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/tags?post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}