baijinswpu 2020-01-01
JSONObject jsonObject = JSONObject.parseObject(jsonstring);
JSONArray jsonArray = jsonObject.getJSONArray("skuList");
for (Object object : jsonArray) {
JSONObject midObject = (JSONObject) object;
BigDecimal price = midObject.getBigDecimal("price");
midObject.put("price", new BigDecimal(String.format("%.2f", price.doubleValue())));
}JSONObject json = JSON.parseObject("{val: 123}");
System.out.println("======before=====");
System.out.println("size: " + json.size());
System.out.println("val: " + json.get("val"));
//直接put相同的key
json.put("val", 234);
System.out.println("======after======");
System.out.println("size: " + json.size());
System.out.println("val: " + json.get("val"));
结果
======before=====
size: 1
val: 123
======after======
size: 1
val: 234