我想用下面的代碼將java對象反序列化爲JSON對象,並且我發現以大寫字母開頭的參數已被寫入雙倍。例如;Java JSON寫入雙倍
Request req = new Request();
req.setMAC("abcdef");
req.setMACParams("term:id:orderno");
req.setOrderNo("999xdef123");
final ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(req);
內JSON字符串的:
{ "MAC":"abcdef","MACParams":"term:id:orderno","OrderNo":"999xdef123","mac":"abcdef","macparams":"term:id:orderno","orderno":"999xdef123" }
所以,我應該怎麼做才能防止這種雙碼?
hmm java是區分大小寫的,'MAC'與'mac'有區別...不知道是什麼問題... – nafas
https://stackoverflow.com/a/37686018/1927832 –
發表一個完整的小例子再現問題。如果您不發佈,我們無法看到您的代碼。你發佈的幾行甚至不是有效的Java代碼。 –