//////////net.sf.json////////// JSONObject sfObject = JSONObject.fromObject(str); //String str = jsonObject.toString(); //转json字符串 Model ecs = (Model) JSONObject.toBean(sfObject, Model.class); //json字符串转java对象 //////////google的Gson////////// //对象转json字符串 Gson gson = new Gson(); String str = gson.toJson(model); Model model = new Gson().fromJson(str, Model.class); //json字符串转java对象 //////////alibaba的fastjson////////// JSONObject jsonObject = JSON.parseObject(str); //String str = jsonObject.toJSONString(); //转json字符串 Model model = JSON.parseObject(s, Model.class); //json字符串转java对象 //json字符串 String str = "{"Average":0.29,"Maximum":0.32,"Minimum":0.25,"instanceId":"i-426auf2hf","timestamp":1449939900000,"userId":"1467232540347717"}"; //实体类 public class Model { private double Average; private double Maximum; private double Minimum; private String instanceId; private long timestamp; private String userId; public double getAverage() { return Average; } public void setAverage(double average) { Average = average; } public double getMaximum() { return Maximum; } public void setMaximum(double maximum) { Maximum = maximum; } public double getMinimum() { return Minimum; } public void setMinimum(double minimum) { Minimum = minimum; } public String getInstanceId() { return instanceId; } public void setInstanceId(String instanceId) { this.instanceId = instanceId; } public long getTimestamp() { return timestamp; } public void setTimestamp(long timestamp) { this.timestamp = timestamp; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } }