我有一个像这样的json字符串
{
"ParValue":100.00,
"RealAmount":100.00,
"SettlementAmt":86.000,
"CardNo":"1707264632031051",
"ReturnCode":1,
"ReturnMsg":"success",
"PlatformOrderNo":"OR1903121512045682711",
"MerchOrderNo":"163244040",
"Sign":"9A9B363CBDABBF14C1F8EFC34CC09D2E"
}
并且我想将其转换为Map对象,所以我使用了这种方式:
HashMap<String,String> map=new Gson().fromJson(response,HashMap.class);
或此
HashMap<String,String> map= new ObjectMapper().readValue(response,HashMap.class);
(响应代表上述json字符串。)
所有数字都已修剪,我需要保留原点值,有什么办法吗?
答案 0 :(得分:0)
因为ParValue
,RealAmount
和SettlementAmt
是JSON数字类型。
您需要先将所有内容转换为字符串类型,然后再使用Gson
:
{
"ParValue":"100.00",
"RealAmount":"100.00",
"SettlementAmt":"86.000",
"CardNo":"1707264632031051",
"ReturnCode":1,
"ReturnMsg":"success",
"PlatformOrderNo":"OR1903121512045682711",
"MerchOrderNo":"163244040",
"Sign":"9A9B363CBDABBF14C1F8EFC34CC09D2E"
}
希望对您有帮助。