public static void main(String[] args) throws Exception {
String jsonStr = "{\"data\": {\"itemNum\": \"S010010001261\", \"itemName\": \"测长度-价目标+价明细+计费项\", \"price\": "
+ "1111111111111"
+ ".11111111111111111111}}";
GoodsPriceVO obj1 =JSON.parseObject(new JSONObject(jsonStr).getString("data"), new TypeReference<GoodsPriceVO>() {
});
GoodsPriceVO obj =JSON.parseObject(JSON.parseObject(jsonStr).getString("data"), new TypeReference<GoodsPriceVO>() {
});
System.out.println(obj1.getPrice()); // 1111111111111.111
System.out.println(obj.getPrice()); // 1111111111111.11111111111111111111
}
org.json.JSONObject
进行字符串通过new JSONObject(str)反序列化会造成BigDecimal精度丢失(只能保留3位小数)
alibaba.fastjson.JSONObject
通过JSON.parseObject(jsonStr)则不会有此问题