{"id":36439,"date":"2024-11-26T08:22:20","date_gmt":"2024-11-26T00:22:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36439\/"},"modified":"2024-11-26T08:22:20","modified_gmt":"2024-11-26T00:22:20","slug":"fastjson-%e8%bd%ac%e6%8d%a2-bigdecimal-%e6%97%b6%e7%b2%be%e5%ba%a6%e4%b8%a2%e5%a4%b1%e9%97%ae%e9%a2%98%ef%bc%9a%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e6%95%b0%e6%8d%ae%e5%a4%b1%e7%9c%9f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36439\/","title":{"rendered":"Fastjson \u8f6c\u6362 BigDecimal \u65f6\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898\uff1a\u5982\u4f55\u907f\u514d\u6570\u636e\u5931\u771f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173114502494467.jpg\" class=\"aligncenter\" title=\"Fastjson \u8f6c\u6362 BigDecimal \u65f6\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898\uff1a\u5982\u4f55\u907f\u514d\u6570\u636e\u5931\u771f\uff1f\u63d2\u56fe\" alt=\"Fastjson \u8f6c\u6362 BigDecimal \u65f6\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898\uff1a\u5982\u4f55\u907f\u514d\u6570\u636e\u5931\u771f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>fastjson\u8f6c\u6362bigdecimal\u65f6\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u4f7f\u7528fastjson\u8f6c\u6362bigdecimal\u7c7b\u578b\u7684\u6570\u636e\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\u7684\u95ee\u9898\uff0c\u4f8b\u5982\u5c0612.0700\u8f6c\u6362\u4e3ajson\u5b57\u7b26\u4e32\u540e\uff0c\u518d\u8f6c\u6362\u56de\u6765\u65f6\u53d8\u4e3a12.7\u3002<\/p>\n<p><strong>\u539f\u56e0\u5206\u6790<\/strong><\/p>\n<p>fastjson\u9ed8\u8ba4\u4f7f\u7528\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u6765\u8868\u793abigdecimal\u7c7b\u578b\u3002\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u5b58\u5728\u7cbe\u5ea6\u9650\u5236\uff0c\u65e0\u6cd5\u7cbe\u786e\u8868\u793a\u67d0\u4e9b\u5c0f\u6570\u3002\u56e0\u6b64\uff0c\u5728\u5c06bigdecimal\u8f6c\u6362\u4e3a\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u65f6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cbe\u5ea6\u4e22\u5931\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u65b9\u6cd5\u662f\u4f7f\u7528fastjson\u7684\u7279\u5b9a\u7279\u6027\u3002fastjson\u4ece1.2.26\u7248\u672c\u5f00\u59cb\uff0c\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n<ul>\n<li>serializerfeature.writebigdecimalaspln\uff1a\u5c06bigdecimal\u8868\u793a\u4e3a\u5b57\u7b26\u4e32\uff0c\u800c\u4e0d\u662f\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u3002<\/li>\n<li>deserializerfeature.usebigdecimal\uff1a\u5728\u53cd\u5e8f\u5217\u5316\u65f6\u5c06\u4e3abigdecimal\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u7279\u6027\u89e3\u51b3\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898\uff1a<\/p>\n<pre>\/\/ \u4f7f\u7528SerializerFeature.WriteBigDecimalAsPlain\u7279\u6027\u8f6c\u6362BigDecimal\u4e3aJSON\nString json = JSON.toJSONString(new BigDecimal(\"12.0700\"), SerializerFeature.WriteBigDecimalAsPlain);\n\n\/\/ \u4f7f\u7528DeserializerFeature.UseBigDecimal\u7279\u6027\u5c06JSON\u89e3\u6790\u4e3aBigDecimal\nBigDecimal bigDecimal = JSON.parseObject(json, BigDecimal.class, DeserializerFeature.UseBigDecimal);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u7279\u6027\uff0c\u53ef\u4ee5\u4fdd\u8bc1bigdecimal\u5728json\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u4e0d\u4f1a\u53d1\u751f\u7cbe\u5ea6\u4e22\u5931\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fFastjson \u8f6c\u6362 BigDecimal \u65f6\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898\uff1a\u5982\u4f55\u907f\u514d\u6570\u636e\u5931\u771f\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\u8f6c\u6362bigdecimal\u65f6\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898 \u5728\u4f7f\u7528fastjson\u8f6c\u6362bigdecimal\u7c7b\u578b\u7684\u6570\u636e\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7cbe\u5ea6\u4e22\u5931\u7684\u95ee\u9898\uff0c\u4f8b\u5982\u5c0612.0700\u8f6c\u6362\u4e3ajson\u5b57\u7b26\u4e32\u540e\uff0c\u518d\u8f6c\u6362\u56de\u6765\u65f6\u53d8\u4e3a12.7\u3002 \u539f\u56e0\u5206\u6790 fastjson\u9ed8\u8ba4\u4f7f\u7528\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u6765\u8868\u793abigdecimal\u7c7b\u578b\u3002\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u5b58\u5728\u7cbe\u5ea6\u9650\u5236\uff0c\u65e0\u6cd5\u7cbe\u786e\u8868\u793a\u67d0\u4e9b\u5c0f\u6570\u3002\u56e0\u6b64\uff0c\u5728\u5c06bigdecimal\u8f6c\u6362\u4e3a\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u65f6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cbe\u5ea6\u4e22\u5931\u3002 \u89e3\u51b3\u65b9\u6cd5 \u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u65b9\u6cd5\u662f\u4f7f\u7528fastjson\u7684\u7279\u5b9a\u7279\u6027\u3002fastjson\u4ece1.2.26\u7248\u672c\u5f00\u59cb\uff0c\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u7279\u6027\uff1a serializerfeature.writebigdecimalaspln\uff1a\u5c06bigdecimal\u8868\u793a\u4e3a\u5b57\u7b26\u4e32\uff0c\u800c\u4e0d\u662f\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u3002 deserializerfeature.usebigdecimal\uff1a\u5728\u53cd\u5e8f\u5217\u5316\u65f6\u5c06\u4e3abigdecimal\u3002 \u793a\u4f8b\u4ee3\u7801 \u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u7279\u6027\u89e3\u51b3\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898\uff1a \/\/ \u4f7f\u7528SerializerFeature.WriteBigDecimalAsPlain\u7279\u6027\u8f6c\u6362BigDecimal\u4e3aJSON String json = JSON.toJSONString(new BigDecimal(&#8220;12.0700&#8221;), SerializerFeature.WriteBigDecimalAsPlain); \/\/ \u4f7f\u7528DeserializerFeature.UseBigDecimal\u7279\u6027\u5c06JSON\u89e3\u6790\u4e3aBigDecimal BigDecimal bigDecimal = JSON.parseObject(json, BigDecimal.class, DeserializerFeature.UseBigDecimal); \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u7279\u6027\uff0c\u53ef\u4ee5\u4fdd\u8bc1bigdecimal\u5728json\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u4e0d\u4f1a\u53d1\u751f\u7cbe\u5ea6\u4e22\u5931\u3002 \u4ee5\u4e0a\u5c31\u662fFastjson \u8f6c\u6362 BigDecimal \u65f6\u7cbe\u5ea6\u4e22\u5931\u95ee\u9898\uff1a\u5982\u4f55\u907f\u514d\u6570\u636e\u5931\u771f\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-36439","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36439","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=36439"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36439\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}