{"id":35838,"date":"2024-11-26T11:55:12","date_gmt":"2024-11-26T03:55:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35838\/"},"modified":"2024-11-26T11:55:12","modified_gmt":"2024-11-26T03:55:12","slug":"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-fastjson-%e8%a7%a3%e6%9e%90-2m-%e5%a4%a7%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%8a%a5%e9%94%99%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35838\/","title":{"rendered":"\u5982\u4f55\u89e3\u51b3 FastJson \u89e3\u6790 2M \u5927\u5b57\u7b26\u4e32\u62a5\u9519\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173077572653485.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u89e3\u51b3 FastJson \u89e3\u6790 2M \u5927\u5b57\u7b26\u4e32\u62a5\u9519\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u89e3\u51b3 FastJson \u89e3\u6790 2M \u5927\u5b57\u7b26\u4e32\u62a5\u9519\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u89e3\u51b3 fastjson \u89e3\u6790 2m \u5927\u5b57\u7b26\u4e32\u62a5\u9519<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 fastjson \u7684 parseobject() \u65b9\u6cd5\u89e3\u6790 2m \u5927\u7684\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u3002\u5bf9\u4e8e\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u4f7f\u7528 jackson<\/strong><\/p>\n<p>\u76ee\u524d\uff0c\u8f83\u591a\u7684\u516c\u53f8\u5df2\u7ecf\u5c06 json \u89e3\u6790\u5de5\u5177\u4ece fastjson \u8fc1\u79fb\u81f3 jackson \u4e2d\u3002jackson \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u3001\u529f\u80fd\u9f50\u5168\u7684 java json \u89e3\u6790\u5e93\uff0c\u652f\u6301\u5904\u7406\u5927\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4f7f\u7528\u793a\u4f8b\uff1a<\/p>\n<pre>objectmapper mapper = new objectmapper();\njsonnode rootnode = mapper.readtree(jsonstring);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8c03\u6574 fastjson \u8bbe\u7f6e<\/strong><\/p>\n<p>\u5982\u679c\u65e0\u6cd5\u8fc1\u79fb\u5230\u5176\u4ed6\u5de5\u5177\uff0c\u5219\u53ef\u4ee5\u5c1d\u8bd5\u8c03\u6574 fastjson \u7684\u8bbe\u7f6e\u4ee5\u63d0\u9ad8\u5176\u89e3\u6790\u6027\u80fd\uff1a<\/p>\n<pre>json.default_parser_feature.getfeatures().put(feature.allow_unquoted_field_names, true);\njson.default_parser_feature.getfeatures().put(feature.allow_single_quotes, true);\njson.default_parser_feature.getfeatures().put(feature.allow_comments, true);\njson.default_parser_feature.getfeatures().put(feature.auto_close_source, true);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u51cf\u5c11\u5b57\u7b26\u4e32\u5927\u5c0f<\/strong><\/p>\n<p>\u5982\u679c\u53ef\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u51cf\u5c11\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u767d\u5b57\u7b26\u6216\u4e0d\u5fc5\u8981\u7684\u6ce8\u91ca\u79fb\u9664\u3002<\/p>\n<p><strong>\u4f7f\u7528\u6d41\u5f0f\u89e3\u6790<\/strong><\/p>\n<p>\u5bf9\u4e8e\u7279\u522b\u5927\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528\u6d41\u5f0f\u89e3\u6790\u7684\u65b9\u6cd5\uff0c\u5c06\u5b57\u7b26\u4e32\u5206\u6279\u6b21\u89e3\u6790\u3002<\/p>\n<p>fastjson \u793a\u4f8b\uff1a<\/p>\n<pre>InputStream is = new FileInputStream(file);\nJSONReader reader = new JSONReader(is);\nJSONToken token = reader.startArray();\nwhile (token != JSONToken.END_ARRAY) {\n    Object value = reader.readObject(Object.class);\n    ...\n    token = reader.nextToken();\n}\nreader.endArray();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5176\u4ed6 json \u5de5\u5177<\/strong><\/p>\n<p>\u9664\u4e86 fastjson \u548c jackson \u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u53ef\u4f9b\u9009\u62e9\u7684 json \u89e3\u6790\u5de5\u5177\uff1a<\/p>\n<ul>\n<li>gson<\/li>\n<li>moshi<\/li>\n<li>smile<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u89e3\u51b3 FastJson \u89e3\u6790 2M \u5927\u5b57\u7b26\u4e32\u62a5\u9519\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>\u89e3\u51b3 fastjson \u89e3\u6790 2m \u5927\u5b57\u7b26\u4e32\u62a5\u9519 \u5728\u4f7f\u7528 fastjson \u7684 parseobject() \u65b9\u6cd5\u89e3\u6790 2m \u5927\u7684\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u3002\u5bf9\u4e8e\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6cd5\uff1a \u4f7f\u7528 jackson \u76ee\u524d\uff0c\u8f83\u591a\u7684\u516c\u53f8\u5df2\u7ecf\u5c06 json \u89e3\u6790\u5de5\u5177\u4ece fastjson \u8fc1\u79fb\u81f3 jackson \u4e2d\u3002jackson \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u3001\u529f\u80fd\u9f50\u5168\u7684 java json \u89e3\u6790\u5e93\uff0c\u652f\u6301\u5904\u7406\u5927\u5b57\u7b26\u4e32\u3002 \u4f7f\u7528\u793a\u4f8b\uff1a objectmapper mapper = new objectmapper(); jsonnode rootnode = mapper.readtree(jsonstring); \u767b\u5f55\u540e\u590d\u5236 \u8c03\u6574 fastjson \u8bbe\u7f6e \u5982\u679c\u65e0\u6cd5\u8fc1\u79fb\u5230\u5176\u4ed6\u5de5\u5177\uff0c\u5219\u53ef\u4ee5\u5c1d\u8bd5\u8c03\u6574 fastjson \u7684\u8bbe\u7f6e\u4ee5\u63d0\u9ad8\u5176\u89e3\u6790\u6027\u80fd\uff1a json.default_parser_feature.getfeatures().put(feature.allow_unquoted_field_names, true); json.default_parser_feature.getfeatures().put(feature.allow_single_quotes, true); json.default_parser_feature.getfeatures().put(feature.allow_comments, true); json.default_parser_feature.getfeatures().put(feature.auto_close_source, true); \u767b\u5f55\u540e\u590d\u5236 \u51cf\u5c11\u5b57\u7b26\u4e32\u5927\u5c0f \u5982\u679c\u53ef\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u51cf\u5c11\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u767d\u5b57\u7b26\u6216\u4e0d\u5fc5\u8981\u7684\u6ce8\u91ca\u79fb\u9664\u3002 \u4f7f\u7528\u6d41\u5f0f\u89e3\u6790 \u5bf9\u4e8e\u7279\u522b\u5927\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528\u6d41\u5f0f\u89e3\u6790\u7684\u65b9\u6cd5\uff0c\u5c06\u5b57\u7b26\u4e32\u5206\u6279\u6b21\u89e3\u6790\u3002 [&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-35838","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35838","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=35838"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35838\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}