JAVA中json对象转JAVA对象

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);

  

猜你喜欢

转载自www.cnblogs.com/pxblog/p/12590079.html