Gson has some odd behavior when I try to convert a string to json. The code below transforms string draft into json responses. Is there a way to prevent gson from adding the '.0 to all integer values?
ArrayList<Hashtable<String, Object>> responses;
Type ResponseList = new TypeToken<ArrayList<Hashtable<String, Object>>>() {}.getType();
responses = new Gson().fromJson(draft, ResponseList);
draft:
[ {"id":4077395,"field_id":242566,"body":""},
{"id":4077398,"field_id":242569,"body":[[273019,0],[273020,1],[273021,0]]},
{"id":4077399,"field_id":242570,"body":[[273022,0],[273023,1],[273024,0]]}
]
responses:
[ {id=4077395.0, body=, field_id=242566.0},
{id=4077398.0, body=[[273019.0, 0.0], [273020.0, 1.0], [273021.0, 0.0]], field_id=242569.0},
{id=4077399.0, body=[[273022.0, 0.0], [273023.0, 1.0], [273024.0, 0.0]], field_id=242570.0}
]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…