String jsonStr = {"UserId":1,"UserName":"张三","Key":12345678910} Gson gson=new Gson(); Map<String, Object> resultMap = gson.fromJson(jsonStr, new TypeToken<Map<String, Object>>(){}.getType() );转换后 UserId=1.0,Key=1.2345678910这个要肿么办,急!!!!!!在线等貌似long型数据默认还转换成16进制了解析前的key:1362312484950解析后的key=1.36231248495E12这是可以直接运行的代码,各位大侠copy到机器上运行一下,看看是不是介个情况,给个回复,谢谢!String jsonStr = "{\"UserId\":1,\"UserName\":\"张三\",\"Key\":12345678910}"; Gson gson = new Gson();Map<String, Object> resultMap = gson.fromJson(jsonStr, new TypeToken<Map<String, Object>>(){}.getType() );for (Iterator<String> it = resultMap.keySet().iterator(); it.hasNext();) {String key = it.next();System.out.println(key+":"+resultMap.get(key));}
2 回答
慕丝7291255
TA贡献1859条经验 获得超6个赞
直接定义一个你的这个用户信息的类吧,不要用Object来描述数据类型
比如:
class User{
private long userId;
private String username;
private long key;
......getters & setters
}
然后用gson.fromJson(jsonStr,User.class)就可以得到user对象了。很方便
添加回答
举报
0/150
提交
取消