1
我有一個字符串轉換JSON字符串到Java對象:Java的
String aString = "[{code:32022,estCode:0,timeZone:CE},{code:59400,estCode:0,timeZone:CE},{code:59377,estCode:0,timeZone:CE},{code:59525,estCode:0,timeZone:CE},{code:59560,estCode:0,timeZone:CE}]"
我試圖用GSON這個字符串轉換爲Map[]
。
我嘗試使用
Gson gsn = new GsonBuilder().create();
Map[] b = gsn.fromJson(aString , Map[].class);
我能夠正確地解析它,我收到輸出
[{code=32022.0, estCode=0.0, timeZone=CE}, {code=59400.0, estCode=0.0, timeZone=CE}, {code=59377.0, estCode=0.0, timeZone=CE}, {code=59525.0, estCode=0.0, timeZone=CE}, {code=59560.0, estCode=0.0, timeZone=CE}]
但值轉換爲double我需要它作爲字符串。 例如:32022轉換爲32022.0我需要它作爲32022有沒有什麼辦法可以在gson中使用ExclusionStrategy
。我看到ExclusionStrategy, shouldSkipClass and shouldSkipField
中只有兩種方法可用,還有其他方法可以使用gson。
請幫
[Gson。將整數反序列化爲整數而不是雙精度](http://stackoverflow.com/questions/17090589/gson-deserialize-integers-as-integers-and-not-as-doubles) – Tschallacka
映射遵循鍵值,但您有3個屬性在你的json元素{code:32022,estCode:0,timeZone:CE},你想要什麼樣的地圖。 –
@ NikhiK.Bansal它是地圖[] – anonymous