{"id":35849,"date":"2024-11-26T10:58:28","date_gmt":"2024-11-26T02:58:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35849\/"},"modified":"2024-11-26T10:58:28","modified_gmt":"2024-11-26T02:58:28","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:\/\/fwq.ai\/blog\/35849\/","title":{"rendered":"\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173077669440519.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/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\u4e86fast\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f\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>fastjson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u62a5\u9519\u7684\u89e3\u51b3\u65b9\u6848 \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\u4e86fast\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 1. \u589e\u52a0\u9ed8\u8ba4\u5927\u5c0f\u9650\u5236 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 json.defaultfieldsize = 1024 * 1024 * 2; \/\/ 2mb \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528\u5b9a\u5236\u7684parserconfig 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 parserconfig config = new parserconfig(); config.setasmenable(false); string json = json.parseobject(json, object.class, config).tostring(); \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528\u5176\u4ed6json\u5de5\u5177 \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 ObjectMapper mapper = new ObjectMapper(); String json = mapper.readValue(json, Object.class).toString(); \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u89e3\u51b3FastJson\u89e3\u6790\u5927\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u7684\u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-35849","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35849","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=35849"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35849\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}