{"id":35816,"date":"2024-11-26T11:30:59","date_gmt":"2024-11-26T03:30:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35816\/"},"modified":"2024-11-26T11:30:59","modified_gmt":"2024-11-26T03:30:59","slug":"fastjson-%e8%a7%a3%e6%9e%90%e5%a4%a7%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%8a%a5%e9%94%99%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35816\/","title":{"rendered":"FastJSON \u89e3\u6790\u5927\u5b57\u7b26\u4e32\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173076913895501.jpg\" class=\"aligncenter\" title=\"FastJSON \u89e3\u6790\u5927\u5b57\u7b26\u4e32\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"FastJSON \u89e3\u6790\u5927\u5b57\u7b26\u4e32\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>fastjson \u89e3\u6790\u5927\u5b57\u7b26\u4e32\u62a5\u9519\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u6211\u4eec\u5728\u4f7f\u7528 fastjson \u89e3\u6790\u8f83\u5927\u7684 json \u5b57\u7b26\u4e32\u65f6\uff0c\u6709\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u3002\u672c\u6587\u5c06\u8ba8\u8bba\u8fd9\u4e2a\u9519\u8bef\u7684\u53ef\u80fd\u539f\u56e0\u53ca\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0<\/strong><\/p>\n<p>\u4f7f\u7528 parseobject() \u65b9\u6cd5\u89e3\u6790 2m \u5927\u5c0f\u7684\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u9519\u8bef\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<ol>\n<li><strong>\u4f7f\u7528 jackson<\/strong><\/li>\n<\/ol>\n<p>\u6587\u7ae0\u4e2d\u63d0\u5230\uff0c\u76ee\u524d\u4f5c\u8005\u6240\u5728\u516c\u53f8\u5df2\u7ecf\u4ece fastjson \u8fc1\u79fb\u5230\u4e86 jackson\u3002jackson \u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684 json \u5904\u7406\u5e93\uff0c\u5b83\u4ee5\u6027\u80fd\u548c\u5904\u7406\u5927\u5b57\u7b26\u4e32\u7684\u80fd\u529b\u800c\u95fb\u540d\u3002\u53ef\u4ee5\u8003\u8651\u5207\u6362\u5230 jackson \u8bd5\u4e00\u8bd5\u3002<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u5206\u5757\u89e3\u6790<\/strong><\/li>\n<\/ol>\n<p>\u5982\u679c\u60a8\u65e0\u6cd5\u5207\u6362\u5230\u5176\u4ed6\u5e93\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u5206\u5757\u89e3\u6790\u6765\u5904\u7406\u5927\u5b57\u7b26\u4e32\u3002\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u8f83\u5c0f\u7684\u5757\uff0c\u7136\u540e\u4f9d\u6b21\u89e3\u6790\u5b83\u4eec\u3002\u8fd9\u6837\u53ef\u4ee5\u51cf\u8f7b\u5185\u5b58\u538b\u529b\u5e76\u907f\u514d\u9519\u8bef\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<pre>string json = \"...\"; \/\/ \u5927\u91cfjson\u5b57\u7b26\u4e32\nobjectmapper mapper = new objectmapper();\nint blocksize = 100000; \/\/ \u5757\u5927\u5c0f\u53ef\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8c03\u6574\nfor (int i = 0; i &lt; json.length(); i += blocksize) {\n    string block = json.substring(i, math.min(i + blocksize, json.length()));\n    mapper.readvalue(block, myobject.class);\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li><strong>\u589e\u52a0\u5806\u5185\u5b58<\/strong><\/li>\n<\/ol>\n<p>\u5982\u679c\u5185\u5b58\u4e0d\u8db3\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u589e\u52a0 java \u865a\u62df\u673a\u7684\u5806\u5185\u5b58\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e -xmx \u9009\u9879\u6765\u5b9e\u73b0\uff1a<\/p>\n<pre>java -Xmx4g ...<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li><strong>\u68c0\u67e5 json \u5b57\u7b26\u4e32\u7684\u683c\u5f0f<\/strong><\/li>\n<\/ol>\n<p>\u786e\u4fdd json \u5b57\u7b26\u4e32\u683c\u5f0f\u6b63\u786e\u3002\u4efb\u4f55\u8bed\u6cd5\u9519\u8bef\u6216\u65e0\u6548\u5b57\u7b26\u90fd\u4f1a\u5bfc\u81f4\u89e3\u6790\u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fFastJSON \u89e3\u6790\u5927\u5b57\u7b26\u4e32\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3\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\u89e3\u51b3\u65b9\u6848 \u6211\u4eec\u5728\u4f7f\u7528 fastjson \u89e3\u6790\u8f83\u5927\u7684 json \u5b57\u7b26\u4e32\u65f6\uff0c\u6709\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u3002\u672c\u6587\u5c06\u8ba8\u8bba\u8fd9\u4e2a\u9519\u8bef\u7684\u53ef\u80fd\u539f\u56e0\u53ca\u89e3\u51b3\u65b9\u6848\u3002 \u95ee\u9898\u63cf\u8ff0 \u4f7f\u7528 parseobject() \u65b9\u6cd5\u89e3\u6790 2m \u5927\u5c0f\u7684\u5b57\u7b26\u4e32\u65f6\u51fa\u73b0\u9519\u8bef\u3002 \u89e3\u51b3\u65b9\u6cd5 \u4f7f\u7528 jackson \u6587\u7ae0\u4e2d\u63d0\u5230\uff0c\u76ee\u524d\u4f5c\u8005\u6240\u5728\u516c\u53f8\u5df2\u7ecf\u4ece fastjson \u8fc1\u79fb\u5230\u4e86 jackson\u3002jackson \u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684 json \u5904\u7406\u5e93\uff0c\u5b83\u4ee5\u6027\u80fd\u548c\u5904\u7406\u5927\u5b57\u7b26\u4e32\u7684\u80fd\u529b\u800c\u95fb\u540d\u3002\u53ef\u4ee5\u8003\u8651\u5207\u6362\u5230 jackson \u8bd5\u4e00\u8bd5\u3002 \u4f7f\u7528\u5206\u5757\u89e3\u6790 \u5982\u679c\u60a8\u65e0\u6cd5\u5207\u6362\u5230\u5176\u4ed6\u5e93\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u5206\u5757\u89e3\u6790\u6765\u5904\u7406\u5927\u5b57\u7b26\u4e32\u3002\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u8f83\u5c0f\u7684\u5757\uff0c\u7136\u540e\u4f9d\u6b21\u89e3\u6790\u5b83\u4eec\u3002\u8fd9\u6837\u53ef\u4ee5\u51cf\u8f7b\u5185\u5b58\u538b\u529b\u5e76\u907f\u514d\u9519\u8bef\u3002 \u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a string json = &#8220;&#8230;&#8221;; \/\/ \u5927\u91cfjson\u5b57\u7b26\u4e32 objectmapper mapper = new objectmapper(); int blocksize = 100000; \/\/ \u5757\u5927\u5c0f\u53ef\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8c03\u6574 for (int i = 0; i &lt; json.length(); i += [&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-35816","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35816","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=35816"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35816\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}