{"id":203508,"date":"2025-05-22T09:06:53","date_gmt":"2025-05-22T01:06:53","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203508\/"},"modified":"2025-05-22T09:06:53","modified_gmt":"2025-05-22T01:06:53","slug":"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3fastjson%e8%a7%a3%e6%9e%90%e5%a4%a7%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203508\/","title":{"rendered":"\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300a\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241110\/1731220066673052624f39b.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>fastjson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u62a5\u9519\u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5728\u4f7f\u7528fastjson\u89e3\u6790\u4f53\u79ef\u8f83\u5927\u7684\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u3002\u8be5\u9519\u8bef\u901a\u5e38\u662f\u7531\u4e8e\u5b57\u7b26\u4e32\u8d85\u8fc7\u4e86fastjson\u5904\u7406\u7684\u9ed8\u8ba4\u5927\u5c0f\u9650\u5236\u5bfc\u81f4\u7684\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u51e0\u79cd\u65b9\u6cd5\u3002<\/p>\n<p><strong>1. \u589e\u52a0\u9ed8\u8ba4\u5927\u5c0f\u9650\u5236<\/strong><\/p>\n<p>fastjson\u63d0\u4f9b\u4e86defaultfieldsize\u5c5e\u6027\uff0c\u7528\u4e8e\u8bbe\u7f6e\u5904\u7406\u5b57\u7b26\u4e32\u7684\u9ed8\u8ba4\u5927\u5c0f\u9650\u5236\u3002\u8981\u589e\u52a0\u9650\u5236\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>json.defaultfieldsize = 1024 * 1024 * 2; \/\/ 2mb<\/pre>\n<p><strong>2. \u4f7f\u7528\u5b9a\u5236\u7684parserconfig<\/strong><\/p>\n<p>fastjson\u8fd8\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684parserconfig\u6765\u89e3\u6790\u5b57\u7b26\u4e32\u3002\u8fd9\u5141\u8bb8\u60a8\u914d\u7f6e\u5904\u7406\u5b57\u7b26\u4e32\u7684\u5177\u4f53\u89c4\u5219\u3002\u8981\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684parserconfig\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>parserconfig config = new parserconfig();\nconfig.setasmenable(false);\nstring json = json.parseobject(json, object.class, config).tostring();<\/pre>\n<p><strong>3. \u4f7f\u7528\u5176\u4ed6json\u5de5\u5177<\/strong><\/p>\n<p>\u9664\u4e86fastjson\uff0c\u8fd8\u6709\u5176\u4ed6\u53ef\u4ee5\u5904\u7406\u5927\u5b57\u7b26\u4e32\u7684json\u5de5\u5177\u3002\u5176\u4e2d\u4e00\u4e2a\u5efa\u8bae\u662fjackson\u3002\u8981\u4f7f\u7528jackson\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>ObjectMapper mapper = new ObjectMapper();\nString json = mapper.readValue(json, Object.class).toString();<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57&#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-203508","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203508","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=203508"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203508\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}