json格式
{userId:'1',message:'2',create_time:'2020-03-28 20:58:11',create_date:'2020-03-28'}
JAVA对象
ChatDTO.java
public class ChatDTO { private String userId; private String message; private String createDate; private String createTime; }
......
get set 方法
调用方法
JSONObject object = JSONObject.fromObject(json); //先转成json对象 ChatDTO chatDTO = (ChatDTO) JSONObject.toBean(object, ChatDTO.class);
JSON数组转集合(JSONArray转list)
List list = (List) JSONArray.toCollection(jsonArray);
集合(List)转JSON数组
JSONArray array=JSONArray.fromObject(list)