首页 > 解决方案 > 避免使用 net.sf.json-lib 使用电子符号

问题描述

我正在使用 com.hynnet.json-lib 将 XML 转换为 JSON。这里的 PB 是对于长整数,这个库使用指数而不是整数。

我可以避免使用这个库还是应该使用另一个库?

我的 XML:

<?xml version="1.0" encoding="ISO-8859-15"?>
<rootTag>
    <_id type="number">7000000001</_id>
</rootTag>

我的转换代码:

XMLSerializer xmlSerializer = new XMLSerializer();
xmlSerializer.clearNamespaces();
xmlSerializer.setSkipNamespaces(true);
xmlSerializer.setForceTopLevelObject(false);
net.sf.json.JSON json = xmlSerializer.read(xmlString);

结果json:

{“_id”:7.000000001E9}

预期的json:

{“_id”:7000000001}

标签: javajsonxmljson-lib

解决方案


enter image description here

Found the reason of such behavior. Double.valueof(String) returns exponential view. Bug on library's side.


推荐阅读